Skip to content

/commands/entra-id/reset-user-password-powershell

Reset a Microsoft Entra ID user password with PowerShell (Update-MgUser -PasswordProfile)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
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.

powershell
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:

powershell
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".
PropertyMeaning
PasswordThe 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

ScenarioRequirement (Microsoft Graph docs)
Least privileged Graph permissionUser-PasswordProfile.ReadWrite.All
Broader permissionsUser.ReadWrite.All, Directory.ReadWrite.All
Delegated, user without admin rolesUser Administrator is the least privileged admin role; Password and Helpdesk Administrators can too
Delegated, any administratorPrivileged Authentication Administrator
App-onlyThe 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

TaskHow
Require MFA before the changeAdd ForceChangePasswordNextSignInWithMfa = $true
Password that never expires (cloud-only user)Update-MgUser -UserId UPN -PasswordPolicies DisablePasswordExpiration
Create a user with a passwordNew-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-Host or generate it, and hand it to the user through a separate channel.
  • The old MSOnline Set-MsolUserPassword and AzureAD Set-AzureADUserPassword cmdlets are retired with their modules; Update-MgUser is the replacement and works in Windows PowerShell 5.1 and PowerShell 7.
  • Run Connect-MgGraph first, 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