Not many things in IT easier than resetting a user’s password, right? Well, I found the Graph SDK PowerShell module’s
Reset-MgUserAuthenticationMethodPassword to be pretty unintuitive. But as with many things, it’s not hard to use once you have an example. I couldn’t find one online, including the usual places (the “example” tab on the resetpassword api article & the cmdlet article), so here ya go:
Connect-MgGraph Select-MgProfile -Name beta $user = email@example.com $method = Get-MgUserAuthenticationPasswordMethod -UserId $user Reset-MgUserAuthenticationMethodPassword -UserId $user -RequireChangeOnNextSignIn -AuthenticationMethodId $method.id -NewPassword "zQ7!Ra3MM6ha"
But why use this cmdlet anyway?
Well, in addition to all the reasons tied to the deprecation of Azure AD Graph, and the potential demise of the msonline & azuread PowerShell modules, Microsoft’s Graph beta API currently stands on a short list of places to reset a password and have it also write back to the on-premises Active Directory.
Supported administrator operations
- Any administrator self-service voluntary change password operation.
- Any administrator self-service force change password operation, for example, password expiration.
- Any administrator self-service password reset that originates from the password reset portal.
- Any administrator-initiated end-user password reset from the Azure portal.
- Any administrator-initiated end-user password reset from the Microsoft Graph API.
Using this API is especially handy if you have a multi-domain hybrid environment, where connecting to the requisite domain controllers is obnoxious, or in scenarios when you don’t have connectivity to the on-premises Active Directory in the first place.
What is an AuthenticationMethodId?
As you can see in the above code, we use
Get-MgUserAuthenticationPasswordMethod to first learn the correct “AuthenticationMethodId”. These are Microsoft’s way to define the various types of authentication you can use with Azure AD, including FIDO2 keys, passwords, the Authenticator app, etc.
As of this writing, there are 9 methods to choose from. When resetting a password, you want passwordAuthenticationMethod, which returns a well-known GUID of
28c10230-6103-485e-b985-444c60001490. In fact, this means you may not need to use
Get-MgUserAuthenticationPasswordMethod, making this approach faster:
Reset-MgUserAuthenticationMethodPassword -UserId $user -RequireChangeOnNextSignIn -AuthenticationMethodId "28c10230-6103-485e-b985-444c60001490" -NewPassword "zQ7!Ra3MM6ha"
Arguably, a cmdlet whose sole purpose is to reset passwords should have this baked in already, but I suppose the current implementation allows for future scalability.