2.1.6. Bulk Management with Microsoft Graph PowerShell
💡 First Principle: A portal is for one change; a script is for a thousand identical changes. Microsoft Graph PowerShell works through Graph's permission model, so every session asks for specific permission scopes — the script can do only what you consented to, which is least privilege applied to automation.
Bulk operations in the portals. The Microsoft Entra admin center has CSV-driven Bulk create (Users > Bulk create, at least User Administrator). Its template requires only Name, User name and Initial password, and it creates member users without sending invitations. Bulk invite for guests requires Email address to invite and a Redirection url. The Microsoft 365 admin center also supports multi-select actions such as assigning licenses to several users at once. These are fine for a one-off import; for anything repeatable, use PowerShell.
The current module. The AzureAD and MSOnline PowerShell modules were deprecated in March 2024; MSOnline was retired in spring 2025, and AzureAD's retirement began in October 2025. Scripts that call Connect-MsolService or Connect-AzureAD are legacy. The replacement is the Microsoft Graph PowerShell SDK (or the Microsoft Entra PowerShell module, built on Graph for compatibility with old AzureAD scripts).
The pattern.
# 1. Connect with only the scopes the task needs
Connect-MgGraph -Scopes "User.ReadWrite.All", "Organization.Read.All"
# 2. Set usage location before licensing
Update-MgUser -UserId "ana@contoso.com" -UsageLocation "US"
# 3. Find the SKU, then assign it
$sku = Get-MgSubscribedSku -All | Where-Object SkuPartNumber -eq "SPE_E5"
Set-MgUserLicense -UserId "ana@contoso.com" -AddLicenses @{SkuId = $sku.SkuId} -RemoveLicenses @()
Points worth knowing:
- Scopes.
User.ReadWrite.Alllets the session create and update users and licenses; reading tenant SKUs withGet-MgSubscribedSkuneedsOrganization.Read.All. - New users.
New-MgUsercreates an account — in practice with a display name, UPN, mail nickname, enabled state and a password profile. - Licenses.
Set-MgUserLicensealways takes both parameters: to remove a license, pass its SKU in-RemoveLicensesand an empty-AddLicenses @{}. AddDisabledPlansinside the license hashtable to turn off individual service plans. - Advanced queries. Some
Get-MgUserfilters —necomparisons and counts, for example — need-ConsistencyLevel eventualplus a count variable. - Sessions.
Revoke-MgUserSignInSessioninvalidates a user's refresh tokens so they must sign in again, which is useful after a security change or a compromise.
⚠️ Exam Trap: Any option built on Connect-MsolService, Set-MsolUserLicense or Connect-AzureAD describes a retired module, even if it would once have worked. Pick the Microsoft Graph PowerShell equivalent — and check that the scopes requested in Connect-MgGraph actually cover the task.
Reflection Question: A script creates 200 users with New-MgUser and then fails on every Set-MgUserLicense call. The connection had User.ReadWrite.All. What's the most likely missing step, and how would you add it to the script?