Unattended access to Exchange Online using a privileged account with MFA enforced

1 min read

I published a PowerShell Gallery script, that will get you through this headache in a jiffy.

UPDATE: Microsoft has patched this hole it seems.
But lets rejoice, because the Exchange Online Management v2 module supports certificate based authentication, so that is much better.
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps

For scheduled tasks or Azure Automation, connecting to Exchange Online has been a must if you are a semi-large company.

But with new security measures like Conditional Access and MFA enforcement coming into their rightful place in most organizations, a lot of these scripts have broken.

A quick fix is just to exclude the account or setup conditions in Conditional Access that would allow a non MFA connection for unattended scripts.

But connecting without exclusions, and keeping the enforcement in place – has been something that has driven many admins to tears.

So I created a sample Runbook that can get you started, using a little known hack to create a new service account, that will bypass MFA even though it is enforced.

The Runbook script can easily be converted to on-premise use for scheduled tasks.

Be aware that as soon as you try to connect with this account interactively, it will break and MFA will block your scripts.

Here is the link to the PowerShell Gallery:

https://www.powershellgallery.com/packages/AzureAutomationAgainstExchangeOnlineWithMFAEnabledAccount/1.0.0
Michael Mardahl

Michael works as a Cloud Architect with APENTO in Denmark. Specializing in customer journeys from classic Infrastructure to Cloud consumption. He has been in the IT industry for more than 20 years, and has experience from a broad range of IT projects. When not at work, Michael enjoys the value of spending time with family and friends, and BLOG's passionately about Enterprise Mobility whenever he has time to spare.

Recent Posts

Passwordless journey with FIDO2 – Part 3 – Engine troubles

After a few months away from bloggin because family and holiday and one self is important to tend to, I…

4 years ago

Conditional Access and the woes of being an external user

Conditional Access and multi tenancy can be tough on anyone... (more…)

4 years ago

Passwordless journey with FIDO2 – Part 2 – Usage experiences

Continuing my ongoing series on passwordless with Azure AD and FIDO2... The story continues on SCConfigMgr.com... :) https://www.scconfigmgr.com/2019/11/18/passwordless-journey-with-fido2-part-2-usage-experiences/

4 years ago

Passwordless journey with FIDO2 – Part 1 – Getting started with security keys

Passwordless with FIDO2 is becoming a real option for enterprises that are adopting the cloud. In this guest blog post…

5 years ago

2 Cool new password policy features in Azure AD Connect

Enabling preview features in Azure AD to extend your on-prem password policy to Azure AD. (more…)

5 years ago

Scripting an Intune policy sync from a Windows client

I was once again fortunate enough to be invited to write another article on how to interact with Intune via…

5 years ago

This website uses cookies to track views anonymously with analytics.