M365 services


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 the 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 OnlineTeams 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), and this also 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 . The script assumes you will connect to Modern Auth, but also supports Basic Auth with the switch -BasicAuthWhen MFA is required, you cannot pass in a credential object.  Although, the Exchange Online module will at least allow you to pass in a UserPrincipalName with MFA. All other modules will ignore credential objects or usernames when MFA is required. So, the script will only pass in UserPrincipalName when MFA is required, and credential object when MFA is NOT required.


.Net and WMF (PowerShell)

You’ll need to install at least .NET Framework 4.5 and Windows Management Framework 5.1 or greater.

M365 Modules

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. )


C:\Scripts\ConnectV2.ps1 -UserPrincipalName_MFA admin@contoso.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 admin@contoso.com -BasicAuth    <—Using BasicAuth, MFA

connect v2

Download script here: ConnectV2