Introduction
The AzureAD PowerShell module has served IT administrators for years, but it’s now officially deprecated in favor of the Microsoft Graph PowerShell SDK. While the change may feel like another “cloud shuffle,” migrating your scripts is not just a compliance move — it’s your ticket to a more powerful, secure, and future-proof automation toolkit. In this post, I’ll walk you through the essentials of converting your Azure AD scripts to Microsoft Graph, with clear side-by-side examples.
Why Migrate?
- Future Support: Microsoft Graph is actively developed; AzureAD is on life support.
- Unified Endpoint: Graph covers Azure AD, Intune, Exchange Online, Teams, and more in one API.
- Security: Better authentication methods, including secure app registrations and least-privilege scopes.
Step 1 – Install Microsoft Graph PowerShell
# Install the module
Install-Module Microsoft.Graph -Scope CurrentUser
# Update if already installed
Update-Module Microsoft.Graph
# Connect with interactive sign-in
Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
# Confirm connection
Get-MgContext
Step 2 – Side-by-Side Script Conversion
Example: Get all Azure AD users
AzureAD Module:
Connect-AzureAD
Get-AzureADUser -All $true
Microsoft Graph:
Connect-MgGraph -Scopes "User.Read.All"
Get-MgUser -All
Example: Get members of a group
AzureAD Module:
$groupId = (Get-AzureADGroup -SearchString "Sales Team").ObjectId
Get-AzureADGroupMember -ObjectId $groupId
Microsoft Graph:
$groupId = (Get-MgGroup -Filter "displayName eq 'Sales Team'").Id
Get-MgGroupMember -GroupId $groupId
Example: Create a new group
AzureAD Module:
New-AzureADGroup -DisplayName "Project A Team" -MailEnabled $false -SecurityEnabled $true -MailNickname "ProjectATeam"
Microsoft Graph:
New-MgGroup -DisplayName "Project A Team" `
-MailEnabled:$false `
-SecurityEnabled `
-MailNickname "ProjectATeam"
Step 3 – Updating Authentication
With Microsoft Graph, you can fine-tune permissions at sign-in instead of granting broad directory access:
Connect-MgGraph -Scopes "User.ReadWrite.All", "Group.ReadWrite.All"
Only request the scopes you actually need — this aligns with least privilege best practices.
Step 4 – Testing and Verification
Before replacing scripts in production, run them in a test tenant or a non-production environment. Compare outputs from AzureAD and Graph to ensure parity.
Conclusion
Migrating from AzureAD to Microsoft Graph PowerShell is more than just a rewrite — it’s a forward-looking investment. Once you adapt, you’ll unlock richer APIs, cross-service automation, and security benefits that AzureAD simply can’t match. My advice? Start small: pick one script, convert it, and test until you’re confident. Once you see the gains, the rest will follow naturally.
For official guidance and best practices from Microsoft, check out these resources:
- Upgrade from Azure AD PowerShell to Microsoft Graph PowerShell — Step-by-step instructions for migrating scripts, highlighting module changes, and cmdlet mapping.
- Important Update: AzureAD PowerShell Retirement — Timeline, impact, and mitigation guidance for the retiring AzureAD and MSOnline PowerShell modules.
© 2012–2025 Jet Mariano. All rights reserved.
For usage terms, please see the Legal Disclaimer.
