SOLVED
Home

Authenticating to O365 using Powershell and MFA

%3CLINGO-SUB%20id%3D%22lingo-sub-3954%22%20slang%3D%22en-US%22%3EAuthenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3954%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20running%20into%20issues%20with%20autheticating%20to%20O365%20on%20Powershell%20and%20in%20this%20case%20my%20account%20has%20been%20enabled%20with%20MFA.%3CBR%20%2F%3EI%20already%20installed%20the%20preview%20from%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fenterprisemobility%2F2015%2F10%2F20%2Fazure-ad-powershell-public-preview-of-support-for-azure-mfa-new-device-management-commands%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.technet.microsoft.com%2Fenterprisemobility%2F2015%2F10%2F20%2Fazure-ad-powershell-public-preview-of-support-for-azure-mfa-new-device-management-commands%2F%3C%2FA%3E%26nbsp%3Band%20the%20authentication%20basically%20works%20but%20then%20comes%20in%20the%20question%20on%20how%20to%20authenticate%20with%20Exchange%20Online%3F%20I%20found%20a%20post%20already%20where%20a%20MSFT%20engineer%20states%20that%20the%20only%20way%20here%20would%20be%20to%20create%20a%20dedicated%20admin%20account%20without%20MFA%20enabled%20but%20we%20strictly%20enabled%20MFA%20on%20admin%20accounts%20for%20security%20reasons.%3CBR%20%2F%3EI%20noticed%20that%20there%20are%20no%20plans%20on%20uservoice%20(but%20some%20suggestions)%20to%20enable%20this.%20Has%20anyone%20already%20found%20another%20solution%20(except%20for%20creating%20another%20account%20without%20MFA)%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3954%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAuthentication%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIdentity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-171084%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-171084%22%20slang%3D%22en-US%22%3E%3CP%3Eeven%20send-message%20not%20working%20without%20MFA.%20Failed%20with%20the%20error%20message%20%22%20No%20mailbox%20available%22.%20any%20thoughts%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-169678%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-169678%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can't.%20That%20cmdlets%2Fmethod%20was%20created%20years%20before%20MFA%20was%20even%20a%20thing.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-169456%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-169456%22%20slang%3D%22en-US%22%3E%3CP%3Ehow%20we%20can%20send%20message%20through%20send-mail%20message%20with%20mfa%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-149242%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-149242%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20having%20issues%20using%20Microsoft%20O365%20reporting%20with%20MFA.%3C%2FP%3E%0A%3CP%3EI%20specifically%20use%20the%20MailProtectionReport%20(Excel)%20and%20it%20does%20not%20seem%20to%20support%20MFA.%3C%2FP%3E%0A%3CP%3EHas%20anyone%20seen%20a%20fix%20for%20this%3F%3C%2FP%3E%0A%3CP%3EI%20do%20have%20another%20admin%20whose%20all%20his%20reports%20are%20run%20automatically.%20What%20will%20he%20have%20to%20change%20or%20will%26nbsp%3Bthis%20affect%20his%20automatic%20reports%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-149074%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-149074%22%20slang%3D%22en-US%22%3EHi%20Dean%2C%3CBR%20%2F%3E%3CBR%20%2F%3Ecan%20you%20explain%20how%20to%20use%20-UserWebLogin%20parameter%20correctly%3F%3CBR%20%2F%3EE.g.%3CBR%20%2F%3Ei%20would%20like%20to%20replace%20it%20in%20%3CBR%20%2F%3EConnect-PnPOnline%20-Url%20%3CA%20href%3D%22https%3A%2F%2Fcontoso.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcontoso.sharepoint.com%3C%2FA%3E%20-Credentials%20(Get-Credential)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-121130%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-121130%22%20slang%3D%22en-US%22%3EYou%20can%20still%20use%20the%20apppassword%20as%20a%20regular%20password%20for%20these%20cases%20until%20MFA%20is%20good%20and%20natively%20supported.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-113332%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-113332%22%20slang%3D%22en-US%22%3E%3CP%3EI%20tried%20to%20get%20send%20emails%20from%20powershell%20when%20MFA%20is%20enabled%2C%20but%20no%20avail.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBackground%3A%3C%2FP%3E%3CP%3EThis%20worked%20when%20my%20account%20did%20not%20have%20MFA%20enabled%20(just%20example)%3A%3C%2FP%3E%3CUL%3E%3CLI%3Etried%20to%20send%20email%20using%26nbsp%3BSend-MailMessage%20-To%20%22xx%40xx.fi%22%20-From%20%24cred.UserName%20-Subject%20%22The%20subject%22%20-Body%20%24body%20-UseSsl%20-Encoding%20UTF8%20-SmtpServer%20%22smtp.office365.com%22%20-Port%20587%20-Credential%20%24cred%20-ErrorVariable%20mailError%3C%2FLI%3E%3C%2FUL%3E%3CP%3EWhen%20I%20enabled%20MFA%20for%20my%20account%20then%20sending%20email%20is%20not%20possible%20through%20powershell%20anymore.%3C%2FP%3E%3CP%3EGetting%20this%20error%3A%26nbsp%3B%3CBR%20%2F%3ESend-MailMessage%20%3A%20The%20SMTP%20server%20requires%20a%20secure%20connection%20or%20the%20client%20was%20not%20authenticated%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFollowed%20this%20article%20and%20one%20hour%20later%20got%20it%20working%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fmt775114(v%3Dexchg.160).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fmt775114(v%3Dexchg.160).aspx%3C%2FA%3E%3C%2FP%3E%3CP%3E-%20run%20into%20problems%20like%20only%20IE%20working%20and%20runas%20IE%20different%20user%20not%20working%3C%2FP%3E%3CP%3E-%20tip%3A%20log%20on%20to%20your%20machine%20with%20the%20account%20you%20have%20as%26nbsp%3B%20Exchange%20admin%20privileges%2C%20don't%20try%20to%20use%20runas%20-functionality%20to%20fool%20your%20browser%2C%20because%20it%20will%20try%20to%20install%20Microsoft%20Exchange%20Online%20Powershell%20Module%20from%20the%20Exchange%20admin%20center%20to%20user%20who%20is%20logged%20on.%20I%20got%20weird%20errors%20like%20this%20is%20already%20installed%20from%20a%20different%20location%20and%20ofcourse%20the%20dirrefent%20zone%20error%20and%20so%20on.%3C%2FP%3E%3CP%3EAfter%20once%20succesfully%20done%20that%20with%20the%20proper%20account%2C%20the%20%22normal%20account%22%20I%20use%20to%20run%20my%20scripts%20in%20this%20machine%20seems%20to%20work%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGot%20the%20Connect-EXOPSSession%20working%20fine%20and%20was%20very%20frustated%20to%20find%20out%20that%20there%20seems%20to%20be%20no%20way%20to%20send%20email%20through%20EXOPSSession.%3C%2FP%3E%3CP%3EIt%20does%20not%20have%20that%20%22inside%22%26nbsp%3B%3CSPAN%3EConnect-EXOPSSession%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26gt%3BGet-Command%20-Module%20tmp_riwbx11w.0ow%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26gt%3B....%3C%2FP%3E%3CP%3E%26gt%3BFunction%20Search-MessageTrackingReport%201.0%20tmp_riwbx11w.0ow%3C%2FP%3E%3CP%3E%26gt%3B(SHOULD%20BE%20here!)%3CBR%20%2F%3E%26gt%3BFunction%20Send-TextMessagingVerificationCode%201.0%20tmp_riwbx11w.0ow%3CBR%20%2F%3E%26gt%3BFunction%20Set-CalendarNotification%201.0%20tmp_riwbx11w.0ow%3C%2FP%3E%3CP%3E%26gt%3B...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20all%20the%20connecting%20to%20Exchange%20Online%20with%20MFA%20was%20for%20nothing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20simply%20conclude%20that%20I've%20to%20use%20local%20Outlook%20to%20send%20messages%20with%20powershell%20if%20MFA%20is%20enabled%3A%3C%2FP%3E%3CP%3E%24Outlook%20%3D%20New-Object%20-ComObject%20Outlook.Application%3CBR%20%2F%3E%24Mail%20%3D%20%24Outlook.CreateItem(0)%3CBR%20%2F%3E%24Mail.To%20%3D%20%22xxx%40xxx.fi%22%3CBR%20%2F%3E%24Mail.Subject%20%3D%20%22Testpost%22%3CBR%20%2F%3E%24Mail.Body%20%3D%22some%20writing%22%3CBR%20%2F%3E%24Mail.Send()%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20summarize%3A%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EIf%20MFA%20enabled%20there%20is%20no%20way%20to%20connect%20to%20Exchange%20Online%20to%20send%20emails%3C%2FLI%3E%3C%2FUL%3E%3CP%3ESolution%3A%3C%2FP%3E%3CUL%3E%3CLI%3Edrop%20the%20MFA%20or%20use%20the%20local%20Outlook%20client%20to%20send%20messages%3C%2FLI%3E%3C%2FUL%3E%3CP%3EHope%20this%20helps%20to%20avoid%20the%20same%20searching%20and%20googling%20to%20find%20out%20there%20is%20no%20cure.%20Better%20yet%20if%20anybody%20has%20answers.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-64830%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64830%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20need%20the%20latest%20SPO%20PowerShell%20module%20version%20though%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D35588%26amp%3B751be11f-ede8-5a0c-058c-2ee190a24fa6%3DTrue%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D35588%26amp%3B751be11f-ede8-5a0c-058c-2ee190a24fa6%3DTrue%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%2C%20SfBO%20PowerShell%20also%20supports%20MFA%20now%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D39366%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D39366%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-64785%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64785%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20works%20well%20now%20for%20using%20PowerShell%20with%20SharePoint%20Online%20and%20MFA%20-%20interactive%2C%20but%20approach%20works%20with%20MFA%20-%20%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Ffp161372.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Ffp161372.aspx%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55890%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55890%22%20slang%3D%22en-US%22%3EI%20think%20that%20you%20will%20need%20to%20use%20a%20Service%20account%20that%20does%20not%20require%20MFA.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20have%20very%20strict%20requirements%2C%20you%20may%20want%20to%20use%20Azure%20Privileged%20Identity%20Management%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Factive-directory-privileged-identity-management-configure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Factive-directory-privileged-identity-management-configure%3C%2FA%3E%20to%20get%20started%20with%20that.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55881%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55881%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20need%20to%20use%20the%20PnP%20SharePoint%20cmdlets%20to%20use%20MFA%20with%20SPO%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20the%20account%20requires%20MFA%2C%20the%20UseWebLogin%20parameter%20is%20needed%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FConnectPnPOnline.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FConnectPnPOnline.md%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55877%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55877%22%20slang%3D%22en-US%22%3E%3CP%3EAnyone%20have%20a%20clue%20as%20to%20how%20to%20use%20MFA%20login%20in%20an%20unattended%20powershell%20script%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20MFA%20working%20fine%20with%20powershell%20interactively%20-%20The%20login%20and%20MFA%20dialogs%20come%20up%20and%20do%20the%20right%20thing%20but%20this%20does%20me%20no%20good%20for%20the%20scheduled%20things%20I%20need%20to%20do%20off-hours.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETIA%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E--Brian%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-54988%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54988%22%20slang%3D%22en-US%22%3E%3CP%3ESeems%20that%20Exchange%20Online%20ist%20MFA%20enabled%20now.%3C%2FP%3E%3CP%3EHave%20a%20look%20at%20this%20article%3A%3C%2FP%3E%3CP%3E%22Connect%20to%20Exchange%20Online%20PowerShell%20using%20multi-factor%20authentication%22%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fmt775114(v%3Dexchg.160).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fmt775114(v%3Dexchg.160).aspx%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-49804%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-49804%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20enabled%20MFA%20for%20our%20Exchange%20Admins%20and%20they%20are%20able%20to%20run%20the%20PowerShell%20okay.%20%26nbsp%3BWe%20are%20finding%20that%20they%20are%20having%20to%20re-auth%20every%2030%20minute%20or%20so.%20%26nbsp%3BAnyone%20know%20if%20there's%20a%20way%20to%20extend%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20is%20Exchange%20PowerShell%20the%20only%20one%20that%20is%20supporting%20MFA%20at%20this%20time%3F%20%26nbsp%3BI'm%20not%20seeing%20anything%20for%20SharePoint...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-37939%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-37939%22%20slang%3D%22en-US%22%3E%3CP%3EWe've%20been%20able%20to%20get%20our%20Office%20365%20Admin%20accounts%20with%20MFA%20enabled%20working%20with%20Powershell%20for%20Exchange%20Online%2C%20Skype%20for%20Business%20etc.....%3CSTRONG%3Ewith%20some%20caveats%3C%2FSTRONG%3E%3A%3C%2FP%3E%3CUL%3E%3CLI%3EThis%20requires%20an%26nbsp%3B%3CSPAN%3EAzure%20AD%20Premium%2C%20Enterprise%20Mobility%20Suite%20or%20Azure%20Multi-Factor%20Authentication%20subscription%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EThe%20admin%20account%20must%20be%20a%20cloud%20only%20account%20(will%20not%20work%20for%20federated%20accounts)%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAssuming%20the%20above%20caveats%20are%20ok%2C%20follow%20the%20below%20steps%20to%20set%20it%20up%3A%3C%2FSPAN%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%3EFollow%20the%20below%20post%20on%20setting%20up%20Azure%20MFA%20contextual%20whitelisting%2C%20you%20will%20need%20to%20whitelist%20all%20ip%20address%20ranges%20that%20powershell%20logins%26nbsp%3Bwill%20come%20from.%20In%20our%20case%20we've%20whitelisted%20all%20of%20our%20companies%20public%20IP%20address%20ranges%3A%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fenterprisemobility%2F2014%2F04%2F25%2Fenhancing-azure-mfa-with-contextual-ip-address-whitelisting%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.technet.microsoft.com%2Fenterprisemobility%2F2014%2F04%2F25%2Fenhancing-azure-mfa-with-contextual-ip-address-whitelisting%2F%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3E%3CSPAN%3EEnable%20MFA%20on%20your%20cloud%20admin%20account%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3ELog%20into%20the%20Office%20365%20portal%20and%20configure%20MFA%20for%20your%20account%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EGo%20to%20this%20link%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fportal.office.com%2Faccount%2F%23security%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fportal.office.com%2Faccount%2F%23security%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EClick%20on%20%3CSTRONG%3EAdditional%20Security%20Verification%20%3C%2FSTRONG%3E(If%20this%20option%20doesn't%20show%20wait%20a%20few%20minutes%20and%20try%20again)%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EClick%20on%20%3CSTRONG%3EUpdate%20my%20phone%20numbers%20used%20for%20account%20security%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3EClick%20on%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3Ethe%3CSTRONG%3E%20app%20passwords%20%3C%2FSTRONG%3Etab%3C%2FLI%3E%3CLI%3EDelete%20the%20default%20app%20password%20that%20was%20created%20(failing%20to%20this%20step%20will%20prevent%20you%20from%20logging%20into%20Office%20365%20services%20via%20powershell).%3C%2FLI%3E%3C%2FUL%3E%3CP%3EThis%20has%20closed%20a%20security%20policy%20breach%20for%20us%2C%20we%20were%20struggling%20with%20it%20for%20a%20while%2C%20the%20missing%20piece%20for%20us%20was%20deleting%20the%20default%20app%20password%20that%20gets%20set%20up%20automatically%20when%20you%20enable%20MFA%20on%20your%20account.%20I%20hope%20that%20this%20can%20help%20other%20people%20struggling%20with%20the%20same%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20ideal%20solution%20will%20come%20when%20Microsoft%20updates%20each%20of%20their%20services%20to%20allow%20federated%20accounts%20with%20MFA%3C%2FP%3E%3CP%3E%3CSPAN%3Eto%20authenticate%20via%20powershell%20(it%20seems%20like%20they%20are%20making%20slow%20progress).%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-28580%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-28580%22%20slang%3D%22en-US%22%3E%3CP%3ETo%20save%20everyone%20from%20having%20to%20read%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F12%22%20target%3D%22_blank%22%3E%40Anna%20Chu%3C%2FA%3E%26nbsp%3Bfull%20post%3A%20there%20is%20now%20an%20Exchange%20Online%20Powershell%20module%20in%20preview%20available%20that%20supports%20MFA.%20I%20just%20tested%20it%20and%20it%20works%20(so%20far)%20as%20expected.%20Go%20to%20%3CA%20href%3D%22http%3A%2F%2Faka.ms%2Fexopspreview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Faka.ms%2Fexopspreview%3C%2FA%3E%20to%20download%20the%20preview.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-27853%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-27853%22%20slang%3D%22en-US%22%3E%3CP%3EMaking%20sure%20you're%20aware%20of%20this%20thread%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FIdentity-Authentication%2FMFA-and-Powershell%2Fm-p%2F23579%2Fthread-id%2F116%2Fhighlight%2Ftrue%23M130%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FIdentity-Authentication%2FMFA-and-Powershell%2Fm-p%2F23579%2Fthread-id%2F116%2Fhighlight%2Ftrue%23M130%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-15462%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-15462%22%20slang%3D%22en-US%22%3E%3CP%3EI%20agree%20that%20all%20PS%20connecting%20to%20O365%20should%20support%20the%20ADAL%20library.%3C%2FP%3E%3CP%3EWaiting%20for%20this%20feature%20already%20more%20than%201%20year.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-12506%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-12506%22%20slang%3D%22en-US%22%3ENot%20for%20connecting%20to%20Exchange%20Online%2C%20that%20is%20purely%20a%20PSSession%20in%20PowerShell%2C%20which%20is%20not%20ADAL%20enabled.%20The%20rest%20of%20the%20services%2C%20yes%2C%20those%20cmdlets%20work%2C%20but%20Exchange%20and%20EOP%2C%20are%20just%20PSSessions.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-12360%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-12360%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20PnP%20powershell%20cmdlets%20can%20be%20use%20with%20MFA%20to%20peform%20many%20actions%20in%20SPO%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%3C%2FA%3E%20and%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FConnectSPOnline.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FOfficeDev%2FPnP-PowerShell%2Fblob%2Fmaster%2FDocumentation%2FConnectSPOnline.md%3C%2FA%3E%20with%20the%20UseWebLogin%20option%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-6828%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-6828%22%20slang%3D%22en-US%22%3E%3CP%3EWhat%20we%20ended%20up%20doing%2C%20was%20configuring%20Conditional%20Access%20MFA%20on%20the%20O365%20Exchange%20Endpoint%20to%20while%20not%20at%20work%20for%20our%20admin%20group.%20%26nbsp%3BThis%20seems%20to%20have%20helped%20us%20from%20within%20the%20Azure%20AD%20Domain%20Applications%20list.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-4847%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-4847%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20with%20you.%26nbsp%3B%20I%20want%20MFA%20on%20all%20my%20admin%20IDs%2C%20yet%20MFA%20is%20not%20enabled%20when%20using%20PowerShell%20for%20O365%20or%20Exchange%20Online.%26nbsp%3B%20Yes%2C%20I%20did%20get%20into%26nbsp%3BAzure%20AD%26nbsp%3Bpowershell%20with%20MFA%20and%20was%20not%20able%20to%26nbsp%3Badminister%20Exchange%20Online%20or%20anything%20else.%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYep.%26nbsp%3B%20Not-so-patiently%20waiting%20for%20MS%20to%20imbed%20MFA%20here.%26nbsp%3B%20I%20love%20the%20extra%20level%20of%20security%20MFA%20adds%20to%20the%20game.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-4684%22%20slang%3D%22en-US%22%3ERE%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-4684%22%20slang%3D%22en-US%22%3EThis%20is%20a%20blocker%20to%20using%20MFA%20on%20our%20admin%20accounts%20too%20-%20we%20need%20to%20run%20scripts%20to%20take%20privileged%20actions%20but%20we%20can't%20enable%20MFA%20for%20those%20privileged%20accounts.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-4043%22%20slang%3D%22en-US%22%3ERe%3A%20Authenticating%20to%20O365%20using%20Powershell%20and%20MFA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-4043%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20module%20only%20helps%20with%20the%20Azure%20AD%20part%2C%20Exchange%2FSkype%2FSharePoint%20PowerShell%20and%20so%20on%20are%20still%20not%20able%20to%20take%20advantage%20of%20MFA.%20And%20it%20has%20been%20requested%20a%20million%20times%20already%2C%20without%20any%20official%20acknowledgement%2Fconfirmation%20on%20MS%20side%20(that%20I'm%20aware%20of).%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

I am running into issues with autheticating to O365 on Powershell and in this case my account has been enabled with MFA.
I already installed the preview from https://blogs.technet.microsoft.com/enterprisemobility/2015/10/20/azure-ad-powershell-public-preview... and the authentication basically works but then comes in the question on how to authenticate with Exchange Online? I found a post already where a MSFT engineer states that the only way here would be to create a dedicated admin account without MFA enabled but we strictly enabled MFA on admin accounts for security reasons.
I noticed that there are no plans on uservoice (but some suggestions) to enable this. Has anyone already found another solution (except for creating another account without MFA)?

24 Replies

The module only helps with the Azure AD part, Exchange/Skype/SharePoint PowerShell and so on are still not able to take advantage of MFA. And it has been requested a million times already, without any official acknowledgement/confirmation on MS side (that I'm aware of).

This is a blocker to using MFA on our admin accounts too - we need to run scripts to take privileged actions but we can't enable MFA for those privileged accounts.

I'm with you.  I want MFA on all my admin IDs, yet MFA is not enabled when using PowerShell for O365 or Exchange Online.  Yes, I did get into Azure AD powershell with MFA and was not able to administer Exchange Online or anything else.   

 

Yep.  Not-so-patiently waiting for MS to imbed MFA here.  I love the extra level of security MFA adds to the game.

What we ended up doing, was configuring Conditional Access MFA on the O365 Exchange Endpoint to while not at work for our admin group.  This seems to have helped us from within the Azure AD Domain Applications list. 

The PnP powershell cmdlets can be use with MFA to peform many actions in SPO, see https://github.com/OfficeDev/PnP-PowerShell and use the https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/ConnectSPOnline.md with the UseWebLogin option

Not for connecting to Exchange Online, that is purely a PSSession in PowerShell, which is not ADAL enabled. The rest of the services, yes, those cmdlets work, but Exchange and EOP, are just PSSessions.

I agree that all PS connecting to O365 should support the ADAL library.

Waiting for this feature already more than 1 year.

Highlighted
Solution

To save everyone from having to read @Anna Chu full post: there is now an Exchange Online Powershell module in preview available that supports MFA. I just tested it and it works (so far) as expected. Go to http://aka.ms/exopspreview to download the preview.

We've been able to get our Office 365 Admin accounts with MFA enabled working with Powershell for Exchange Online, Skype for Business etc.....with some caveats:

  • This requires an Azure AD Premium, Enterprise Mobility Suite or Azure Multi-Factor Authentication subscription
  • The admin account must be a cloud only account (will not work for federated accounts)

 

Assuming the above caveats are ok, follow the below steps to set it up:

  • Follow the below post on setting up Azure MFA contextual whitelisting, you will need to whitelist all ip address ranges that powershell logins will come from. In our case we've whitelisted all of our companies public IP address ranges: 

https://blogs.technet.microsoft.com/enterprisemobility/2014/04/25/enhancing-azure-mfa-with-contextua...

 

  • Enable MFA on your cloud admin account
  • Log into the Office 365 portal and configure MFA for your account
  • Go to this link: https://portal.office.com/account/#security
  • Click on Additional Security Verification (If this option doesn't show wait a few minutes and try again)
  • Click on Update my phone numbers used for account security
  • Click on the app passwords tab
  • Delete the default app password that was created (failing to this step will prevent you from logging into Office 365 services via powershell).

This has closed a security policy breach for us, we were struggling with it for a while, the missing piece for us was deleting the default app password that gets set up automatically when you enable MFA on your account. I hope that this can help other people struggling with the same issue.

 

The ideal solution will come when Microsoft updates each of their services to allow federated accounts with MFA

to authenticate via powershell (it seems like they are making slow progress).

We enabled MFA for our Exchange Admins and they are able to run the PowerShell okay.  We are finding that they are having to re-auth every 30 minute or so.  Anyone know if there's a way to extend this?

 

Also, is Exchange PowerShell the only one that is supporting MFA at this time?  I'm not seeing anything for SharePoint...

Seems that Exchange Online ist MFA enabled now.

Have a look at this article:

"Connect to Exchange Online PowerShell using multi-factor authentication"

https://technet.microsoft.com/en-us/library/mt775114(v=exchg.160).aspx

Anyone have a clue as to how to use MFA login in an unattended powershell script?

 

I have MFA working fine with powershell interactively - The login and MFA dialogs come up and do the right thing but this does me no good for the scheduled things I need to do off-hours.

 

TIA

 

--Brian

You need to use the PnP SharePoint cmdlets to use MFA with SPO, see https://github.com/SharePoint/PnP-PowerShell,

 

If the account requires MFA, the UseWebLogin parameter is needed, see https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/ConnectPnPOnline.md

I think that you will need to use a Service account that does not require MFA.

If you have very strict requirements, you may want to use Azure Privileged Identity Management, see https://docs.microsoft.com/en-us/azure/active-directory/active-directory-privileged-identity-managem... to get started with that.

This works well now for using PowerShell with SharePoint Online and MFA - interactive, but approach works with MFA - https://technet.microsoft.com/en-us/library/fp161372.aspx

I tried to get send emails from powershell when MFA is enabled, but no avail. 

 

Background:

This worked when my account did not have MFA enabled (just example):

  • tried to send email using Send-MailMessage -To "xx@xx.fi" -From $cred.UserName -Subject "The subject" -Body $body -UseSsl -Encoding UTF8 -SmtpServer "smtp.office365.com" -Port 587 -Credential $cred -ErrorVariable mailError

When I enabled MFA for my account then sending email is not possible through powershell anymore.

Getting this error: 
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated

 

Followed this article and one hour later got it working:

https://technet.microsoft.com/en-us/library/mt775114(v=exchg.160).aspx

- run into problems like only IE working and runas IE different user not working

- tip: log on to your machine with the account you have as  Exchange admin privileges, don't try to use runas -functionality to fool your browser, because it will try to install Microsoft Exchange Online Powershell Module from the Exchange admin center to user who is logged on. I got weird errors like this is already installed from a different location and ofcourse the dirrefent zone error and so on.

After once succesfully done that with the proper account, the "normal account" I use to run my scripts in this machine seems to work fine.

 

 

Got the Connect-EXOPSSession working fine and was very frustated to find out that there seems to be no way to send email through EXOPSSession.

It does not have that "inside" Connect-EXOPSSession:

>Get-Command -Module tmp_riwbx11w.0ow

 

>....

>Function Search-MessageTrackingReport 1.0 tmp_riwbx11w.0ow

>(SHOULD BE here!)
>Function Send-TextMessagingVerificationCode 1.0 tmp_riwbx11w.0ow
>Function Set-CalendarNotification 1.0 tmp_riwbx11w.0ow

>...

 

So all the connecting to Exchange Online with MFA was for nothing.

 

I simply conclude that I've to use local Outlook to send messages with powershell if MFA is enabled:

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "xxx@xxx.fi"
$Mail.Subject = "Testpost"
$Mail.Body ="some writing"
$Mail.Send()

 

To summarize: 

  • If MFA enabled there is no way to connect to Exchange Online to send emails

Solution:

  • drop the MFA or use the local Outlook client to send messages

Hope this helps to avoid the same searching and googling to find out there is no cure. Better yet if anybody has answers.

You can still use the apppassword as a regular password for these cases until MFA is good and natively supported.
Hi Dean,

can you explain how to use -UserWebLogin parameter correctly?
E.g.
i would like to replace it in
Connect-PnPOnline -Url https://contoso.sharepoint.com -Credentials (Get-Credential)

I'm having issues using Microsoft O365 reporting with MFA.

I specifically use the MailProtectionReport (Excel) and it does not seem to support MFA.

Has anyone seen a fix for this?

I do have another admin whose all his reports are run automatically. What will he have to change or will this affect his automatic reports?

how we can send message through send-mail message with mfa

You can't. That cmdlets/method was created years before MFA was even a thing.

even send-message not working without MFA. Failed with the error message " No mailbox available". any thoughts

Related Conversations
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies