This is an updated blog/script that takes advantage of new EXO v2 module, and MFA. (Note: my old blog here, is not compatible with MFA). This NEW script will connect to main M365 services in a single PowerShell window, which are available across E3 and E5 licenses. The main services are (Azure AD [v1 & v2], Sharepoint Online, Skype 4B Online, Exchange Online, Teams and Compliance Center). You’ll need to install prerequisites before you can connect to all services. (Note: Compliance Center will connect with prefix ‘cc’ so as not to overlap. For example Get-ccMailbox, but this affects unique cmdlets such as Get-ccComplianceCase)
The M365 account you use to connect with PowerShell must be a member of the Global Admin role or relevant admin roles.
There are some key things to know about this script. By default, it will only connect to EXO, Azure AD (v1) and Compliance Center. If you want to connect to the other services, just add the switch -all . Also, the script assumes you will connect to Modern Auth, however if you have an old tenant (still using Basic Auth) then you can specify a switch -BasicAuth. Another thing to know, if MFA is required, you cannot pass in a credential object. Exchange Online module is the only module that can pass in a UserPrincipalName with MFA, this includes the legacy MFA module (which uses Basic Auth) and the new EXO v2 module (uses Modern Auth). All other modules will ignore credential objects or usernames when MFA is required. So, the script is set that way, pass in credential object when MFA is NOT required, otherwise pass in UserPrincipalName.
.Net and WMF (PowerShell)
You’ll need to install at least .NET Framework 4.5 and Windows Management Framework 5.1 or greater.
You need to install modules that are required for Azure AD (v1 & 2), Teams, SharePoint Online, Skype for Business Online, and Exchange Online v2 (see below). (Note: All modules, except Skype, require PowerShellGet for installation. )
- Exchange Online Legacy MFA (Basic Auth) (NOT Required. For Reference Only.)
- Exchange Online v2
- Azure AD PowerShell v1 (MSOL)
- Azure AD PowerShell v2 (AzureAD)
C:\Scripts\ConnectV2.ps1 -UserPrincipalName_MFA email@example.com -ALL <—Using ModernAuth, MFA
C:\Scripts\ConnectV2.ps1 -Credential_NoMFA (Get-Credential) <—Using ModernAuth
C:\Scripts\ConnectV2.ps1 -Credential_NoMFA (Get-Credential) -BasicAuth <—Using BasicAuth
C:\Scripts\ConnectV2.ps1 -UserPrincipalName_MFA firstname.lastname@example.org -BasicAuth <—Using BasicAuth, MFA
Download script here: ConnectV2