This is a short article about how to install and use the AzureAD PowerShell module. This is the module that provides all the cmdlets like “Get-AzureADUser”.If you want to script with O365 and Azure objects (users, groups…), then AzureAD is one of the important modules for you. There is another article on this blog with a general comparison of the modules needed for O365 and Azure AD scripting.
To start with the AzureAD module, you should have Powershell 5.1 on the system. So you are fine on Windows 10 systems and Windows Server 2016 and newer – on older Windows OS version you have to install Powershell 5.1. If you don’t know your current PowerShell version, use this:
Unfortunately, you cannot use the AzureAD module with PowerShell Core 6 (it will crash the powershell) – and also under Powershell 7, this module is not supported.
Get it Going
Open an elevated PowerShell console (“Run as Administrator”). Then just use the Install-Module cmdlet:
If you install a PowerShell module from the online repositories for the very first time, then the process informs you that the NuGet provider must be installed first, please agree here with “y”.
There might be another warning that the repository is untrusted. You can agree with “y” because the module is an official Microsoft module in the PowerShell Gallery (which is the repository).
The module is now downloaded from the PowerShell Gallery. Size is less than 10 MB, so it shouldn’t take too long…
After the module installation, you are ready to go. In your script, you always have to import the module first – then you can authenticate to your tenant:
Now you are ready to access the objects in your tenant:
Preview Version of AzureAD
The AzureAD PowerShell modules are available in a General Availability version (AzureAD module) and a preview version (AzureADPreview module). The AzureADPreview module contains some new cmdlets and features, but these could be changed or even be removed when an “AzureADPreview” version finally becomes the normal GA “AzureAD”. Most of the cmdlets are identical to the GA version.
So, for testing and playing around, you should go for the most modern AzureADPreview – in productive environments, it’s better to use the stable AzureAD module. But it is not possible to install both modules on the same machine – you have to choose! If you installed the normal AzureAD
You can install and use the AzureADPreview module in exactly the same way as the AzureAD:
Don’t forget that Microsoft provides quite regular updates to the AzureAD Modules, so it’s always good to check if there’s an update. You can compare the outputs of Get-InstalledModule (local version) and Find-Modul (version in the Powershell Gallery). If you want to update, do not use “Update-Module” or do not try to uninstall the old version. Performing a normal Install-Module with the -force switch is enough, this will replace the old version with the current one:
Install-Module AzureAD -force
The official version history site: Microsoft’s version history for both modules, AzureAD and AzureADPreview.
The version list of the developers: AzureAD Module Site in the PowerShell Gallery.
AzureAD and PowerShell 7
The AzureAD module is officially not supported on PowerShell 7. You can install and even import the module but you cannot use it:
Sorry, there’s nothing you can do for a workaround. Neither with a compatibility switch like for the MSOL PowerShell module – nor with the usage of AzureADPreview.
I wrote a few blog posts about typical error messages when installing and connecting the cloud PowerShell modules:
- Troubleshooting “The following commands are already available on this system”
- Troubleshooting “No match was found for the specified criteria and module name”
Microsoft provides an online reference about all cmdlets which come with the AzureAD module, as well as a detailed description how to install and use the AzureAD PowerShell module: