Install Azure PowerShell Module and Connect to Your Tenant - WindowsTips.net - Windows Tips and Tricks with Geek

Thursday, June 24, 2021

Install Azure PowerShell Module and Connect to Your Tenant

 The easiest way to install Azure PowerShell Modules is to install it from the PowerShell Gallery using PowerShellGet.

Hint. There are currently two modules for managing Azure: Azure Az and AzureRM. AzureRM was released in December of 2018 and is currently deprecated. Therefore, for now, you only need to use the Azure Az module. If you have AzureRM installed on your computer, uninstall it with the command:

Uninstall-Module -Name AzureRm -AllVersions

Prerequisites:

  • Windows PowerShell version 5.1 or newer should be installed on your computer. On Windows 10, PowerShell 5.1 is installed by default. You can check the current PowerShell version with the command: $PSVersionTable.PSVersion On Windows 8.1 and Windows Server 2012 R2, Windows Management Framework 5.0 must be installed to upgrade to PowerShell 5.1;

install azure powershell

  • .NET Framework 4.7.2 or newer must be installed on your device. If the following PowerShell script returns True, it means that .Net 4.7.2 or higher is installed:
    (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction SilentlyContinue).Release -ge 461808

install az module

  • PowerShellGet 1.1.2.0 or higher must be installed on your computer. Check the current version with the command:
    Get-Module -Name PowerShellGet -ListAvailable | Select-Object -Property Name,Version,Path

azure active directory module for windows powershell

In our example, PowerShellGet version 1.0.0.1 is installed. Update it with the command:

Install-Module PowerShellGet –Force

install azure ad powershell

You are now ready to install the Azure PowerShell modules. Microsoft recommends installing Azure PowerShell only for an active user of the computer with the command:

Install-Module -Name Az -AllowClobber -Scope CurrentUser

azure ad powershell module

You will receive a warning about using an untrusted repository. You need to select Yes or Yes to All:

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’?

Then confirm the NuGet installation.

If you want to install Azure Module for all users of the computer, run:

Install-Module -Name Az -AllowClobber -Scope AllUsers

To check if the Azure Az module is installed on your computer (and to check its version) use the command:

Get-InstalledModule -Name Az | select Name, Version

install azure powershell module

To update the Azure AD PowerShell Module to the latest version, run the command:

Update-Module -Name Az

To import the installed Az module into the current PowerShell session, run the command:

Import-Module -Name Az

You are now ready to connect to your Azure tenant. Run the command:

Connect-AzAccount

Log in with your credentials (it’s recommended using MFA).

windows azure active directory module for windows powershell

If your account is associated with multiple Azure tenants, or your status is Cloud Solution Provider (CSP), you can specify the tenant ID to connect:

Connect-AzAccount -Tenant '****-****-****-****’

You can list the subscriptions available to your account using the command:

Get-AzSubscription

No comments:

Post a Comment