How to enable Azure MFA for Online PowerShell Modules that don’t support MFA?
In this blog post I will look into how you can accomplish Azure Multi-Factor Authentication for Admins even though the Online PowerShell Module don’t support it. The key to do this is to implement and use Azure AD Privileged Identity Management, which is an Azure AD Premium P2 / EMS E5 feature.
The Problem
Administration of Online Services with PowerShell can be done with different PowerShell modules or for some scenarios setting up a remote session to the Online Service. But not all scenarios support Azure MFA natively. A quick overview of the main modules that DO support Azure MFA today:
- Azure PowerShell. Supports Azure MFA with Add-AzureAccount.
- Azure Resource Manager PowerShell. Supports Azure MFA with Login-AzureRMAccount.
- Azure Active Directory PowerShell MSOnline Module. Supports Azure MFA with Connect-MSOLService.
- The Public Preview of Azure AD v2 PowerShell (https://azure.microsoft.com/en-us/updates/azure-ad-new-powershell-cmdlets-preview/ ). Supports Azure MFA with Connect-AzureAD.
- Azure Rights Management Service PowerShell. Supports Azure MFA with Connect-AadrmService.
- SharePoint Online PowerShell. Supports Azure MFA with Connect-SPOService.
- Update Dec. 2016: Exchange Online Remote PowerShell now supports Azure MFA with Connect-EXOPSSession, read more https://gotoguy.blog/2017/01/12/exchange-online-powershell-with-modern-authentication-and-azure-mfa-available/ .
All of these above supports Azure MFA as long as you are not passing in a Credential object. There are also more advanced scenarios for programmatic access with Access Token and Certificates that I will not cover here for some of these modules. The main thing is that when you create a Credential object with Get-Credential, and pass that in as a Parameter to the above modules, Azure MFA will not work if the Admin user has been configured to use that. We’ll see some examples later in the blog. Note also that if you have an older version of MSOnline or Aadrm which required the Online Sign-In assistant, these will not work with Azure MFA and you must upgrade to the latest versions. So what about the modules and scenarios that don’t support Azure MFA. These are mainly Office 365 and Remote PowerShell:
- Exchange Online Remote PowerShell (Update, a new Exchange Online Remote PowerShell module has now been released, but for a normal PowerShell remoting session this would still not support Azure MFA)
- Skype for Business Online Remote PowerShell
- Office 365 Security & Compliance Center Remote PowerShell
In these scenarios you must create a Credential object, and pass that in as a parameter when connecting to the service, thus blocking the use of Azure MFA.
A Security Best Practice for Admins
Today I just don’t find it acceptable for Admin accounts for any Online Service like Azure or Office 365, to not use Multi-Factor Authentication or some other protection mechanism, and just depend on username and password! In addition to that, as an Organization you have to have control of your identities, employees and admins come and go, I have seen many times that Organizations still have Admin accounts for users that have left the company for a long time ago. Most Organizations have Directory Synchronization from local Active Directory to Azure AD, making it possible to synchronize your local admin accounts. You then have a choice: Should I use synchronized admin accounts for the Admin Roles in Azure/Office 365? Or should I only create Cloud only admin accounts for this purpose? My security best practice is to use a combination of both, so that:
- Synchronized On-Premise Admin Accounts for the most important, permanent and sensitive admin accounts, like Global Admins, Security Admins, Azure Subscription Admins and more. These accounts will be set up to require Azure MFA, as these accounts possibly can connect to On-Premise resources.
- Cloud Only Admins accounts for Role Based Administration, additional temporary Global Admins or other scenarios for intermittent Azure and Office 365 administration. These accounts will not be set up for Azure MFA, but I use Azure AD Privileged Identity Management to require Azure MFA when activating the role. Some of these accounts also includes service accounts for Directory Synchronization, Intune Connector etc.
The Solution
I have found that the best way to protect both type of Admin accounts is to use the Azure AD Privileged Identity Management and Azure MFA in combination so that:
- In general all of the permanent Admin Accounts with a few exceptions are required to use Azure MFA. These Admin accounts can use all PowerShell modules that support MFA when connecting.
- Role-based admins (for example Exchange Admins, Skype for Business Admins,..) are set up to be Temporary/Eligible Admins in Azure AD Privileged Identity Management, which require Azure MFA at activation time. After the admin role is activated, he or she can use the PowerShell modules/remote sessions that don’t support Azure MFA natively.
The downside of this solution is that Azure AD Privileged Identity Management require an Azure AD Premium P2 license or Enterprise Mobility E5 license, which will be Generally Available Sept 15th. Azure MFA are free to use for Admin accounts for Online Services.
How to set it up
In the following steps I will show how to set this up and how it will work. For the purpose for this demo I will work with my demo environment with the tenant name elven.onmicrosoft.com. I have also configured directory synchronization from my on-premise Active Directory, these users will have a UPN suffix of elven.no.
In my environment I have a fictional character called Ola Nordmann. Ola is an Exchange Admin in our Hybrid Exchange environment, and needs permissions to administer Exchange Online in Office 365 both via the management portal and via Exchange Online PowerShell.
Ola has these two accounts now in Azure AD:

Configure Multi-Factor Authentication
The easiest way to enable MFA for a user is via the Office 365 Admin portal at https://portal.azure.com
. In the user list I find and select the admin user I want to enable MFA for:






Configure Admin Role
Next, I will give Ola Nordmann the Exchange Administrator role, so that he can administer Exchange Online.
Back in the Office Admin portal I see that the user now has no roles:



Log on and activate multi-factor authentication method for admin user
Now I will log on the ola.admin@elven.no
account to https://portal.office.com
.
Since this admin account has been configured for MFA, I must set that up now:










Try to access Exchange Online PowerShell with MFA enabled admin
First, a quick look back at the multi-factor authentication administration page, where the admin user status has now been updated to Enforced. This happens after the users have been enabled for MFA, and after they have successfully configured their authentication methods. Enforced means that they will now be required to do MFA when authenticating against online services:



Configure Azure AD Privileged Identity Management for Exchange administrators
At this next step I log in as a Global Administrator, and if I haven’t already added the Privileged Identity Management solution, I can add it from the Azure Marketplace:







Log on as admin user without activation
When I log in to the Office 365 portal with the ola.admin@elven.onmicrosoft.com
, I will see that this user is just a normal user with no admin links, This is expected as the user hasn’t activated the Exchange Administrator role.

Activate the Exchange Administrator Role
Next I go to the Azure portal at https://portal.azure.com
still logged on as ola.admin@elven.onmicrosoft.com
. First I need to add the Privileged Identity Management solution:






Log on to the Office 365 Portal and Exchange Admin Center after activation
After activation, I should log off and back on with my activated admin role account, and this time I will see the Exchange Admin portal:

Log on to Exchange Online PowerShell after activation
And finally, I can start an Exchange Online PowerShell Session with my activated account. First I get my credential:



| |
Summary
At the end of this long blog post, we can summarize that we have accomplished the solution of adding Azure Multi-Factor Authentication for scenarios where the PowerShell Module or Remoting Session does not natively support it. This is made possible by using Azure AD Privileged Identity Management, and by making some role administrators eligible and require MFA when activating. This way they have verified their identity before they connect with the Credential object. This is just one scenario where both Azure AD MFA and Privileged Identity Management can be used together for increased security and reduce the attack surface of having vulnerable permanent administrator accounts and roles. I hope this blog post have been informative and helpful, please reach out or comment if you want to know more or have any questions.