Using PowerShell for managing Azure resources

From PUBLIC-WIKI
Revision as of 12:07, 15 November 2018 by Eyales (talk | contribs)
Jump to navigation Jump to search

How to configure PowerShell for managing Azure resources (Windows platform)

  • Login to the machine using privileged account.
  • From command prompt, run the command below to invoke PowerShell:
powershell
Note: You need to run cmd.exe or PowerShell.exe as administrator.
  • Run the command below to find out the current PowerShell version:
$PSVersionTable.PSVersion
  • In-case you currently have version older than 5.1, follow the article below to locate the download URL for upgrading to the latest version of PowerShell:
https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6
Also, review the article below for PowerShell installation pre-requirements:
https://docs.microsoft.com/en-us/powershell/scripting/setup/windows-powershell-system-requirements?view=powershell-5.1
  • Run the below command to check if you have PowerShellGet installed on your system:
Get-Module PowerShellGet -list | Select-Object Name,Version,Path
  • In-case you don’t have PowerShellGet, run the commands below:
Install-PackageProvider Nuget –Force
Install-Module -Name PowerShellGet –Force
For more information about installation or upgrade of PowerShellGet, see:
https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
  • Run the command below to install Azure cmdlet for PowerShell:
Install-Module AzureRM -Force
  • Run the command below to set the execution policy:
Set-ExecutionPolicy Unrestricted -Force
  • Run the command below to import the AzureRM module:
Import-Module AzureRM
  • Run the command below to update to the latest AzureRM module:
Update-Module -Name AzureRM -Force
  • To view the installed versions of AzureRM, run the command below:
Get-Module -Name AzureRM -List | select Name,Version
  • To remove older versions of AzureRM, run the command below (update the command to the relevant version you wish to uninstall):
Get-InstalledModule -Name AzureRM -RequiredVersion 6.10.0 | Uninstall-Module

How to configure PowerShell for managing Azure resources (CentOS platform)

  • Login to the machine using privileged account.
  • Run the command below to register the RedHat repository:
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
Note: The above command should be written in a single line
  • Run the command below to install PowerShell:
sudo yum install -y powershell
  • From command prompt, run the command below to invoke PowerShell:
sudo pwsh
Note: You need to run cmd.exe or PowerShell.exe as administrator.
  • Run the command below to find out the current PowerShell version:
$PSVersionTable.PSVersion
  • Run the below command to check if you have PowerShellGet installed on your system:
Get-Module PowerShellGet -list | Select-Object Name,Version,Path
  • In-case you don’t have PowerShellGet, run the commands below:
Install-Module -Name PowerShellGet –Force
For more information about installation or upgrade of PowerShellGet, see:
https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
  • Run the command below to install Azure cmdlet for PowerShell:
Install-Module Az -Force
  • Run the command below to import the AzureRM module:
Import-Module Az
  • Run the command below to update to the latest AzureRM module:
Update-Module -Name Az -Force