Endjin - Home

How to use the AzureAD module in PowerShell Core

by James Broome

AzureAD-Module-in-PowerShell-Core-P1-1024px

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.

1. Register the Posh Test Gallery package source

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.

About the author

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 provides technology strategy, data insights and engineering support to organisations of all sizes - from disruptive B2C start-ups, to global financial institutions - to enable them to deliver on the vision of a modern, data-driven, cloud-first organisation.