Skip to content
James Broome By James Broome Director of Engineering
How to use the AzureAD module in PowerShell Core

Whilst some of the Azure Active Directory PowerShell for Graph module (AzureAD) functionality has been rolled into the new Azure PowerShell Az module (Az), it's not currently (and might never be) a replacement for the full power of what you can achieve with AzureAD.

So, there's every chance you'll find yourself needing to use both side-by-side, which is absolutely fine until you want to do that using the new cross-platform PowerShell Core.

At time of writing there's no publicly available version of AzureAD that works with PowerShell Core - however, this post will explain that it is indeed possible to use this module functionality, as well as detailing the steps needed to get it working.

Whilst there's no PowerShell Core supported version of AzureAD in the central PowerShell Gallery, there is a private preview version available in the Posh Test Gallery. Whilst this is indeed an "internal" gallery, for testing purposes, this preview version of the module is already in use in the Azure Cloud Shell, so it's a fairly safe bet that a) it's working as you expect and b) it will eventually move out of preview status.

If you haven't used the Posh Test Gallery before, you'll need to register it as an additional package source in your PowerShell Core environment.

2. Install the AzureAD.Standard.Preview module

Now that the gallery is registered, you can install the preview version of the AzureAD module - which is called AzureAD.Standard.Preview - just as you would with any regular, non-preview module. PowerShell Core will automatically check the Posh Test Gallery as well for this module when you call the Install-Module cmdlet.

3. Import the installed module

Now that the module is installed, you need to explicitly import it into your current session. You shouldn't need to do this, as typically a module is automatically imported after install, however, in this case it doesn't seem to happen as expected. The easiest way to do this is to use the RootModule property of the installed module which points to the AzureAD.Standard.Preview.psm1 file in whatever local file path your installation points to (in my case C:\Users\JamesBroome\Documents\PowerShell\Modules\AzureAD.Standard.Preview\0.1.599.7)

4. Use the module!

That's it - now that the module is installed and imported you should be able to use it in your PowerShell Core session exactly as you'd expect. Here's the full source code as a reusable PowerShell function:

Conclusion

This post has shown that whilst no public version of the AzureAD module is compatible with PowerShell Core, it's pretty easy to install and use the preview version of AzureAD.Standard.Preview module from the Posh Test Gallery in order to retain that functionality in your PowerShell Core scripts.

Hopefully an official version will become available soon, but in the meantime, the steps above will allow you to continue using AzureAD functionality.

Azure Weekly is a summary of the week's top Microsoft Azure news from AI to Availability Zones. Keep on top of all the latest Azure developments!

James Broome

Director of Engineering

James Broome

James has spent nearly 20 years delivering high quality software solutions addressing global business problems, with teams and clients across 3 continents. As Director of Engineering at endjin, he leads the team in providing technology strategy, data insights and engineering support to organisations of all sizes - from disruptive B2C start-ups, to global financial institutions. He's responsible for the success of our customer-facing project delivery, as well as the capability and growth of our delivery team.