Saturday, August 18, 2018

Install Azure PowerShell and Execute Commands

Cloud computing is very trending technology in today IT industry.Among all these cloud computing services azure is one of the most used cloud computing service. If you have experience with azure may have created azure VM s for various project requirements. Most of the azure users know how to create azure VM using azure portal but most of them haven't tried to create azure VM using ARM templates.You can refer my post Create Azure Virtual Machine which explain how to create azure VM using azure portal.This post will present you setting up azure PowerShell before start working with ARM template.Within this article you will learn how to install azure PowerShell and execute few PowerShell commands.

  1. First launch  Windows PowerShell run as administrator
  2. 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
  3. 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
  4. 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
    policychange
  5. 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.
    installazurerm&nugrt
  6. 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.
    logintorm
    • After enter correct user credentials  account Information will be displayed
    accountinfo
    • Now you are ready to execute azure PowerShell commands.Let’s try few commands
    Command 1: get-azurermvm | select name
    Purpose:  get names of available azure VMs
    getvmname
    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”
    PurposeCreate 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.

No comments:

Post a Comment