Execute power shell script with MFA

%3CLINGO-SUB%20id%3D%22lingo-sub-1733595%22%20slang%3D%22en-US%22%3EExecute%20power%20shell%20script%20with%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1733595%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20of%20our%20tenant%20has%20enabled%20MFA%20for%20administrator%20account%2C%20can%20I%20get%20help%20on%20how%20to%20execute%20the%20PowerShell%20script%20with%20MFA%20enabled%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1733595%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1735485%22%20slang%3D%22en-US%22%3ERe%3A%20Execute%20power%20shell%20script%20with%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1735485%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F807814%22%20target%3D%22_blank%22%3E%40mytech1982%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20should%20be%20a%20matter%20of%20connecting%20to%20SP%20online%20by%20running%20the%20below%20as%20Administrator%20in%20Powershell%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24orgName%3D%22%3CNAME%20of%3D%22%22%20your%3D%22%22%20office%3D%22%22%20365%3D%22%22%20organization%3D%22%22%3E%22%3CBR%20%2F%3EConnect-SPOService%20-Url%20%3CA%20href%3D%22https%3A%2F%2F%24orgName-admin.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F%24orgName-admin.sharepoint.com%3C%2FA%3E%3C%2FNAME%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20then%20signing%20in%20with%20the%20Admin%20details%20%2B%20the%202FA%20code%20in%20the%20prompts%20when%20they%20pop%20up.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20covered%20in%20more%20detail%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fsharepoint%2Fsharepoint-online%2Fconnect-sharepoint-online%3Fview%3Dsharepoint-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fsharepoint%2Fsharepoint-online%2Fconnect-sharepoint-online%3Fview%3Dsharepoint-ps%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20entirely%20sure%20why%20the%20more%20usual%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24adminUPN%3D%22%3CTHE%20full%3D%22%22%20email%3D%22%22%20address%3D%22%22%20of%3D%22%22%20a%3D%22%22%20sharepoint%3D%22%22%20administrator%3D%22%22%20account%3D%22%22%3E%22%3CBR%20%2F%3E%24orgName%3D%22%3CNAME%20of%3D%22%22%20your%3D%22%22%20office%3D%22%22%20365%3D%22%22%20organization%3D%22%22%3E%22%3CBR%20%2F%3E%24userCredential%20%3D%20Get-Credential%20-UserName%20%24adminUPN%20-Message%20%22Type%20the%20password.%22%3CBR%20%2F%3EConnect-SPOService%20-Url%20https%3A%2F%2F%24orgName-admin.sharepoint.com%20-Credential%20%24userCredential%3C%2FNAME%3E%3C%2FTHE%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2C%20doesn't%20seem%20to%20work%20with%202FA%20even%20though%20it's%20the%20same%20basic%20command%20but%20with%20more%20details%20provided%20up%20front.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Hi,

 

One of our tenant has enabled MFA for administrator account, can I get help on how to execute the PowerShell script with MFA enabled

1 Reply

@mytech1982 

It should be a matter of connecting to SP online by running the below as Administrator in Powershell:

 

$orgName="<name of your Office 365 organization, example: contosotoycompany>"
Connect-SPOService -Url https://$orgName-admin.sharepoint.com

 

And then signing in with the Admin details + the 2FA code in the prompts when they pop up. 

 

This is covered in more detail here https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?v... 

 

I'm not entirely sure why the more usual,

 

$adminUPN="<the full email address of a SharePoint administrator account, example: jdoe@contosotoycompany.onmicrosoft.com>"
$orgName="<name of your Office 365 organization, example: contosotoycompany>"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential

 

, doesn't seem to work with 2FA even though it's the same basic command but with more details provided up front.