The AzureAD, MSOnline and AzureADPreview PowerShell modules are scheduled for deprecation. The schedule has changed a couple of times. To be prepared, admins should get going with the new Microsoft Graph PowerShell SDK module. However, the Microsoft Graph PowerShell SDK works differently. There's a learning curve that has proven steep. Many admins who have walked the path before you have reported many issues.
This blogpost series aims to help you on your journey. Together with Aleksandar Nikolic, a Microsoft MVP with an extensive background in PowerShell, we're providing tips and tricks on finding your way through typical questions, situations and annoyances.
In the previous blogpost in this series, Aleksandar and I shared how to install the generally available v1 of the Microsoft Graph PowerShell SDK. However, there is also the v2 of the Microsoft Graph PowerShell SDK.
About Microsoft Graph PowerShell SDK v2
v2 of the Microsoft Graph PowerShell SDK was released as a Public Preview on December 21st, 2022. v2 is a pre-release version of the next version of the Microsoft Graph PowerShell SDK that aims to enhance the experience while interacting with the Microsoft Graph API.
In terms of interacting with the Microsoft Graph API, v2 offers separate cmdlets targeting the two different versions of the Graph API, v1.0 and beta. v1 of the Microsoft Graph PowerShell SDK contains the Select-MgProfile cmdlet and offers interactions to both Graph API versions through the same *-Mg* cmdlets. Because the way this is built, both the v1.0 and beta API functionality is part of the Microsoft.Graph module. If you ever wondered why v1 of the Microsoft Graph PowerShell SDK requires that huge amount of disk space… there's your answer.
In v2, the Select-MgProfile cmdlet is no more. When you install the Microsoft.Graph module, only the functionality to interact with v1.0 of the Graph API is installed. If you want to interact with the beta version of the Microsoft Graph API, you'll (also) need the Microsoft.Graph.Beta module.
The Get-MgUser cmdlet simply targets v1.0 of the Graph API. The Get-MgBetaUser cmdlet targets the beta version of the Graph API.
Note:
The beta version of the Graph API is unsupported. In the context of the Microsoft Graph API, this means that Microsoft may change, break, redirect or even remove functionality without notifications in advance.
Splitting up Microsoft.Graph and Microsoft.Graph.Beta isn’t just good news for hard disk space. It also makes sense when interacting with the Graph API to access relatively new functionality in Azure AD.
Let’s use an example based on a common scenario for Azure AD admins; report on the usage of self-service password reset (SSPR) and multi-factor authentication (MFA). For this purpose, the Get-MgReportCredentialUserRegistrationDetail cmdlet is available.
With v1 of the Microsoft Graph PowerShell SDK, you’d use the following commands:
$userPrincipalName = Get-MgUser -Filter "startswith(displayName,'Diego')" | Select-Object -ExpandProperty UserPrincipalName
Get-MgReportCredentialUserRegistrationDetail -Filter "UserPrincipalName eq '$userPrincipalName'" -All
However the latter command would fail, because The term 'Get-MgReportCredentialUserRegistrationDetail' is not recognized as the name of a cmdlet, function, script file, or operable program. Instead, what we need to do is:
$userPrincipalName = Get-MgUser -Filter "startswith(displayName,'Diego')" | Select-Object -ExpandProperty UserPrincipalName
Select-MgProfile -Name beta
Get-MgReportCredentialUserRegistrationDetail -Filter "UserPrincipalName eq '$userPrincipalName'" -All
To get the point across for v2 of the Microsoft Graph PowerShell SDK, you’d use the following commands:
$userPrincipalName = Get-MgUser -Filter "startswith(displayName,'Diego')" | Select-Object -ExpandProperty UserPrincipalName
Get-MgBetaReportCredentialUserRegistrationDetail -Filter "UserPrincipalName eq '$userPrincipalName'" -All
We specifically specify to use the cmdlet from the Microsoft.Graph.Beta module to avoid any problems.
Our recommended practices for v2
In the second part of this blogpost series, we discussed the different requirements for the Microsoft Graph PowerShell SDK in Windows PowerShell 5.x and PowerShell 7.x. The requirements haven’t changed for v2 of the Microsoft Graph PowerShell SDK.
If you want to get going with v2 of the Microsoft Graph PowerShell SDK, it is our recommendation to:
- Use v1 of the Microsoft Graph PowerShell SDK in Windows PowerShell 5.1
- Use v2 of the Microsoft Graph PowerShell SDK in PowerShell 7.
That way you will avoid any potential conflict between v1 and v2. And, have both versions installed on your system, so that you can easily use and test the latest preview v2 version of the Microsoft Graph PowerShell SDK while still having access to the stable v1 version of the Microsoft Graph PowerShell SDK.
Login