Skip to content
Menu

User Lost Their Phone - Reset MFA Methods

Deletes four kinds of MFA method. If none that satisfy MFA remain, the user must register again at an MFA sign-in. The dry run lists the methods first.

User lost their phone - reset MFA methods is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review User lost their phone - reset MFA methods. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: User.Read.All, UserAuthenticationMethod.ReadWrite.All, User.RevokeSessions.All
Changes thingsChanges what it runs on

What It Does

This script changes things. For the one account in UserPrincipalName it deletes the registered phone numbers, Microsoft Authenticator registrations, software OATH tokens and FIDO2 security keys. With no method left, Microsoft prompts the user to register again the next time they sign in where MFA is required. It never deletes the password method, a Windows Hello for Business credential, the email method used for password reset or a Temporary Access Pass, and it never touches any other account.

It is a dry run, listing every method it would delete, until DryRun=false and Approve=reset-user-mfa-methods are both set. It refuses to delete more than MaxChanges (default 25) in one run. Before the first deletion it saves the method IDs and types, with no phone numbers and no secrets, as JSON under the Backups folder of the MSPOutpost data folder and prints the file name. A deleted method cannot be restored: the user registers a new one.

With RevokeSessions=true it also revokes the user's sign-in sessions and refresh tokens, but only in a run that removes methods. Alternate and office phone numbers go before the mobile number, because Microsoft will not delete a mobile number while an alternate remains. It then reads the methods back, up to six times, and ends in an error if any are still there.

Running it again finds nothing to delete and reports already reset, so a second run changes nothing, not even the sessions. If a method cannot be deleted the run stops with an error naming it, and methods already deleted stay deleted. Microsoft says a phone number cannot be deleted while it is the user's default MFA method: ask the user to change the default, or delete it in the Entra admin center. For a user who holds an admin role, give the app's service principal the Privileged Authentication Administrator role, or the run stops with a 403.

Before You Run It

  • Create an app registration with User.Read.All and UserAuthenticationMethod.ReadWrite.All, plus User.RevokeSessions.All if you will use RevokeSessions, and grant admin consent.
  • Check you are dealing with the real user before you remove their methods.
  • Run a dry run first and read the list of methods it would delete.
  • Give the app the Privileged Authentication Administrator role if the user holds an admin role.
  • Tell the user they will be asked to register again at their next sign-in.
  • If the account may be compromised, also run invoke-compromised-account-containment.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: High. It is a dry run unless you set both DryRun=false and Approve=reset-user-mfa-methods, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
  • What it changes: Deletes the user's phone, Microsoft Authenticator, software OATH and FIDO2 authentication methods; optionally revokes their sign-in sessions.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute.
  • Example answer: "Removed 3 MFA method(s) from ann@contoso.com; sessions revoked; she registers again at next sign-in"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The client tenant: its ID (a GUID) or a domain such as contoso.onmicrosoft.com. Required.
  • ClientId: The Application (client) ID of the app registration that holds the Graph permissions. Required.
  • CertificateThumbprint: Thumbprint of the app's certificate (private key in LocalMachine\My or CurrentUser\My). Preferred. When empty, the app secret is read from the environment variable ClientSecret (a secure/hidden RMM field; never an argument).
  • UserPrincipalName: The user's sign-in name, for example ann@contoso.com. Required.
  • RevokeSessions: true to also revoke the user's sign-in sessions and refresh tokens in the same run. Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

reset-user-mfa-methods.ps1 · 1075 lines · 60.7 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.