/commands/entra-id/reset-user-password-powershell
Reset a Microsoft Entra ID user password with PowerShell (Update-MgUser -PasswordProfile)
- tool
- Microsoft Entra ID
- versions
- Microsoft.Graph.Users 2.41.2
- os
- windows, linux, macos
To reset a user's password in Microsoft Entra ID with PowerShell, connect to Microsoft Graph with the User-PasswordProfile.ReadWrite.All scope and pass a -PasswordProfile hashtable to Update-MgUser. Set ForceChangePasswordNextSignIn = $true so the user replaces the temporary password at the next sign-in, which is what Microsoft recommends.
Connect-MgGraph -Scopes 'User-PasswordProfile.ReadWrite.All'
$temp = Read-Host 'Temporary password for adele@contoso.com'
Update-MgUser -UserId adele@contoso.com -PasswordProfile @{
Password = $temp
ForceChangePasswordNextSignIn = $true
}Replace the UPN with yours. The cmdlet prints nothing on success; Microsoft Graph answers 204 No Content. The temporary password must meet the tenant's password policy (strong passwords by default).
The PasswordProfile object
The block lists the properties of the password profile type and the parameter type in Microsoft.Graph.Users 2.41.2, offline:
Import-Module Microsoft.Graph.Users
'-PasswordProfile type: ' + (Get-Command Update-MgUser).Parameters['PasswordProfile'].ParameterType.Name
[Microsoft.Graph.PowerShell.Models.MicrosoftGraphPasswordProfile].GetProperties() |
Where-Object Name -ne 'EntityItem' | ForEach-Object { '{0,-38} {1}' -f $_.Name, ($_.PropertyType.Name -replace '`1', '') }
try { Update-MgUser -UserId adele@contoso.com -PasswordProfile 'text' -ErrorAction Stop } catch { $_.Exception.Message }Output
-PasswordProfile type: IMicrosoftGraphPasswordProfile ForceChangePasswordNextSignIn Nullable ForceChangePasswordNextSignInWithMfa Nullable Password String Cannot process argument transformation on parameter 'PasswordProfile'. Cannot convert the "text" value of type "System.String" to type "Microsoft.Graph.PowerShell.Models.IMicrosoftGraphPasswordProfile".
| Property | Meaning |
|---|---|
| Password | The new password, as plain text in the request (sent over TLS) |
| ForceChangePasswordNextSignIn | $true: the user must choose a new password at the next sign-in |
| ForceChangePasswordNextSignInWithMfa | $true: the user must also complete MFA before changing it |
A string is rejected during parameter binding, as the last line shows: -PasswordProfile needs a hashtable (or a MicrosoftGraphPasswordProfile object). Keys inside the hashtable are not checked the same way, so a misspelled key is not rejected before the request is sent: copy the property names exactly.
Permissions and roles
| Scenario | Requirement (Microsoft Graph docs) |
|---|---|
| Least privileged Graph permission | User-PasswordProfile.ReadWrite.All |
| Broader permissions | User.ReadWrite.All, Directory.ReadWrite.All |
| Delegated, user without admin roles | User Administrator is the least privileged admin role; Password and Helpdesk Administrators can too |
| Delegated, any administrator | Privileged Authentication Administrator |
| App-only | The permission plus at least the User Administrator role assigned to the app |
Which admin can reset whom is defined by role: a Helpdesk Administrator, for example, cannot reset a Global Administrator. If the role is too weak, Graph returns Insufficient privileges to complete the operation.
Variants
| Task | How |
|---|---|
| Require MFA before the change | Add ForceChangePasswordNextSignInWithMfa = $true |
| Password that never expires (cloud-only user) | Update-MgUser -UserId UPN -PasswordPolicies DisablePasswordExpiration |
| Create a user with a password | New-MgUser -PasswordProfile ... (see the New-MgUser page) |
Pitfalls
- Federated users cannot have their password set through
passwordProfile. - Avoid putting the password in the script or in command history; read it with
Read-Hostor generate it, and hand it to the user through a separate channel. - The old MSOnline
Set-MsolUserPasswordand AzureADSet-AzureADUserPasswordcmdlets are retired with their modules; Update-MgUser is the replacement and works in Windows PowerShell 5.1 and PowerShell 7. - Run
Connect-MgGraphfirst, or every call ends with Authentication needed. Please call Connect-MgGraph.
FAQ
Which permission does a password reset need?
User-PasswordProfile.ReadWrite.All is the least privileged Microsoft Graph permission for the passwordProfile property. In delegated use the signed-in admin also needs a role that may reset that user, such as User Administrator for users without admin roles.
Can I reset the password of a federated user this way?
No. Microsoft's Update user reference states that passwordProfile cannot be used for federated users; their password lives with the identity provider they sign in through.
What does ForceChangePasswordNextSignInWithMfa do?
It works like ForceChangePasswordNextSignIn, but the user must first complete multifactor authentication before being made to change the password at the next sign-in.
Sources
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/microsoft.graph.users/update-mguser
- learn.microsoft.comlearn.microsoft.com/en-us/graph/api/user-update
- learn.microsoft.comlearn.microsoft.com/en-us/graph/api/resources/passwordprofile
- learn.microsoft.comlearn.microsoft.com/en-us/graph/api/resources/users