With Microsoft deprecating the AzureAD and MSOnline modules in favor of the Microsoft Graph PowerShell SDK, it's essential for IT admins to transition their scripts and workflows. One of the most common tasks—creating users—was traditionally done using the New-MsolUser cmdlet. But now, New-MgUser is the way forward.
In this article, we’ll break down the transition, help you understand the differences, and give you updated script examples for a smooth migration.
New-MsolUser -DisplayName "John Doe" `
-UserPrincipalName "john.doe@yourdomain.com" `
-FirstName "John" `
-LastName "Doe" `
-Password "Password123" `
-ForceChangePassword $true
For bulk creation, you might’ve imported from a CSV:
$users = Import-Csv -Path "Users.csv"
foreach ($user in $users) {
New-MsolUser -DisplayName $user.DisplayName `
-UserPrincipalName $user.UserPrincipalName `
-Password $user.Password `
-ForceChangePassword $true
}
The equivalent task using the Microsoft Graph module (New-MgUser) would look like this:
Basic User Creation
New-MgUser -DisplayName "John Doe" `
-UserPrincipalName "john.doe@yourdomain.com" `
-MailNickname "john.doe" `
-PasswordProfile @{Password="Password123"; ForceChangePasswordNextSignIn=$true} `
-AccountEnabled
Bulk User Creation$users = Import-Csv -Path "Users.csv"
foreach ($user in $users) {
$userParams = @{
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
MailNickname = $user.MailNickname
AccountEnabled = $true
PasswordProfile = @{
Password = $user.Password
ForceChangePasswordNextSignIn = $true
}
}
New-MgUser -BodyParameter $userParams
}
Old (New-MsolUser) | New (New-MgUser) |
Uses individual parameters for each field | Encourages using a hashtable via -BodyParameter |
Accepts plain -Password parameter | Uses PasswordProfile as a nested object |
Limited scope to Azure AD | Part of Microsoft.Graph.Users module |
Deprecated by Microsoft | Built on Microsoft Graph API – broader capabilities |
Device Management | Actively developed and supported |
The transition from New-MsolUser to New-MgUser may seem like a shift at first, but it brings enhanced capabilities, modern practices, and better compatibility with Microsoft 365 services.
Microsoft Graph is the future—and the sooner your scripts make the leap, the more future-proof your automation becomes.
Need more migration guides or scripts? Visit M365Corner.com — your trusted resource for everything Graph PowerShell!
© Your Site Name. All Rights Reserved. Design by HTML Codex