Install Azure PowerShell
This guide will walk you through the process of installing Azure PowerShell on your local machine. Azure PowerShell provides cmdlets that you can use to manage your Azure resources.
Prerequisites
- An Azure account. If you don't have one, sign up for a free account.
- A supported version of Windows or macOS.
- PowerShell 7.2 or later installed.
Installation Methods
You can install Azure PowerShell using the PowerShellGet module, which is the recommended method. Alternatively, for certain scenarios, you might use other package managers.
Method 1: Using PowerShellGet (Recommended)
This method installs the Az
module, which is the current and recommended module for managing Azure resources with PowerShell.
-
Open PowerShell as Administrator:
Search for 'PowerShell' in the Windows Start menu, right-click on 'Windows PowerShell', and select 'Run as administrator'. On macOS or Linux, open your terminal.
-
Install the Az PowerShell module:
Run the following command to install the latest version of the
Az
module:Install-Module -Name Az -AllowClobber -Scope CurrentUser
If you are prompted to install the NuGet provider, type
Y
and press Enter.If you are prompted to install from an untrusted repository, type
Y
and press Enter. -
Verify the installation:
After the installation is complete, you can verify it by listing the installed Az modules:
Get-Module -ListAvailable -Name Az
-
Connect to your Azure account:
To start managing your Azure resources, connect to your Azure account:
Connect-AzAccount
This command will open a browser window for you to sign in to your Azure account.
Method 2: Installing for Specific Cloud Environments (e.g., Azure Government)
If you need to manage resources in specific Azure cloud environments like Azure Government, you'll need to specify the AzEnvironmentName
parameter during installation and connection.
# Install the Az.Accounts module for Azure Government
Install-Module -Name Az.Accounts -Scope CurrentUser -AzEnvironmentName AzureUSGovernment
# Connect to Azure Government
Connect-AzAccount -EnvironmentName AzureUSGovernment
Managing Modules
You can update the Az
module to the latest version using:
Update-Module -Name Az
To uninstall the Az
module:
Uninstall-Module -Name Az -Force -Verbose
Troubleshooting Common Issues
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
(with administrator privileges) to allow scripts from trusted sources.
- Proxy Servers: If you are behind a proxy, ensure that PowerShell is configured to use your proxy settings.
- Internet Connectivity: A stable internet connection is required for downloading and authenticating modules.
For more detailed information and advanced scenarios, please refer to the official Azure PowerShell documentation.