Powershell and MFA

Mark Verhunce 1 Reputation point

Is there any way to auto populate the email address / username for the mfa window when running connect-azuread?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,356 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,394 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dillon Silzer 54,286 Reputation points

    Hi @Mark Verhunce

    You could use an app password:

    (cited from https://www.varonis.com/blog/connect-to-office-365-powershell)

    How To Set an App Password for Microsoft 365 and PowerShell

    To configure an app password:

    • Navigate to https://aka.ms/mfasetup and select the App Passwords menu.
    • Select the Create button and give the app password a name to indicate its purpose.
    • After clicking Next, the window will display the app password, and you should save it in a password credential manager as you won’t be able to retrieve it.

    This will allow your PowerShell script to use your username and app password as a credential to authenticate. Note: You must have app passwords enabled in your tenant.


    If this is helpful please accept answer.