- First launch Windows PowerShell run as administrator
- Before proceed you need to find your current execution policy and PowerShell version
- Azure PowerShell requires PowerShell version 5 or greater.so first execute following command and find your current PowerShell version
- $PSVersionTable.PSVersion
- If you have lower version.you have to upgrade existing PowerShell version
- Now let’s find out what is your current execution policy is.
- Execution policy is part of security strategy of PowerShell.It controls level of access you have to the computer.To find the execution policy execute following command
- Get-ExecutionPolicy
- If your Execution policy is Restricted you will not be allowed to install azure PowerShell.You must set the PowerShell Execution Policy from Restricted to RemoteSigned or Unrestricted to allow local PowerShell scripts to be run.So you can change it by using following command.You can change execution policy to RemoteSigned as shown in the image below
- Set-ExecutionPolicy RemoteSigned
- Now we can install azure PowerShell by executing following command
- Install-Module azureRM
- After execute above command you may be asked to install NuGet provider packages before install azure PowerShell .Then select Yes to install NuGet provider packages and after NuGet provider package installation completed you will be asked to confirm azureRM installation. Then Select yes.
- Now azure PowerShell installation is completed.Now we can execute azure PowerShell commands.
- Before execute azure PowerShell commands we need to login to azure account.To do that execute following command
- Login-AzureRmAccount
- After execute this command you will be asked for user credentials to login to azure account.Then enter user credentials.
- After enter correct user credentials account Information will be displayed
- Now you are ready to execute azure PowerShell commands.Let’s try few commands
Purpose: get names of available azure VMs
Command 2: get-azurermvm
Purpose: get details of available VMs.You can get details such as Resource Group Name,VM name,Location,VM Size,OS Type,NIC,Provisioning State
Command 3: New-AzureRmResourceGroup –Name myresourcegroup –Location “East US”
Purpose: Create new resource group called myresourcegroup in East US region
Command 4: get-azurermvm –ResourceGroupName myresource | foreach {start-azurermvm –Name $_.name –resourcegroupname myresource
Purpose: If you have already created VMs you can use above command to start VMs.above command says to start VMs inside Resource Group called myresource
Now you have an idea how to work with azure PowerShell commands and ready to work with ARM template.I will share you How to create azure VM using ARM template in my next post.
0 Comments