Wondering how to install the Azure PowerShell module? Here’s how we do it.
Here at Bobcares, we have seen several such PowerShell related queries as part of our Server Management Services for web hosts and online service providers.
Today, we’ll take a look at how to install Azure Powershell.
A few facts about Azure PowerShell
Azure PowerShell manages and administers Azure resources from the command line. Also, it is a set of cmdlets.
This is mainly used to build automated tools that use the Azure Resource Manager model.
It is written in .NET Standard.
How to install the Azure PowerShell module
Now let’s take a look at how our Support Engineers install the Azure PowerShell.
Azure PowerShell works with PowerShell 6.2.4 and later on all platforms. It is also supported by PowerShell 5.1 on Windows.
In order to check the PowerShell version, run the command:
$PSVersionTable.PSVersion
Here are the steps to install the Azure PowerShell module
Installing using PowerShellGet cmdlets method
This is the most preferred method.
We run the below command from a PowerShell session:
if (Get-Module -Name AzureRM -ListAvailable) {
Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
'Az modules installed at the same time is not supported.')
} else {
Install-Module -Name Az -AllowClobber -Scope CurrentUser
}
The PowerShell Gallery isn’t configured by default. For the first time when you use the PowerShellGallery, you see the below prompt.
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the `Set-PSRepository` cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
For the above prompt, you can either answer ‘Yes’ or ‘Yes to All’ and continue with the installation.
In case, if you wish to install the module for all users on a system then you need elevated privileges. For that, start the PowerShell session using Run as an administrator in Windows or use the sudo command on macOS or Linux:
if (Get-Module -Name AzureRM -ListAvailable) {
Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
'Az modules installed at the same time is not supported.')
} else {
Install-Module -Name Az -AllowClobber -Scope AllUsers
}
Install Azure PowerShell Offline
Sometimes, in some environments connecting to the PowerShell Gallery isn’t possible. In such cases, you can install it using the offline method. Here are the steps for the same.
First, download the modules to another location in your network and use that as an installation source.
Then download the Azure PowerShell MSI to a machine connected to the network. After that, copy the installer to systems without access to PowerShell Gallery. Make a note that the MSI installer only works for PowerShell 5.1 on Windows.
Finally, save the module with Save-Module to a file share, or save it to another source and manually copy it to other machines:
Save-Module -Name Az -Path ‘\\server\share\PowerShell\modules’ -Force
[Need any further assistance with PowerShell queries? – We are here to help you.]
Conclusion
Today, we saw how our Support Engineers install the Azure PowerShell module using the cmdlets method and through offline.
0 Comments