Connecting to all Office 365 Services with PowerShell and Multi Factor Authentication
You cannot have full control of your Office 365 tenant, if you do not know how to use PowerShell for Office 365, since there are a ton of configurations, and settings that are only configurable via PowerShell, and not via the Office 365 Admin Center! Not to mention, all the automation capabilities that PowerShell allows you to script, so you save time and money. Since most accounts admin accounts are (or should be) configured with Multi Factor Authentication, here is a small guide on how to connect to all the Office 365 services with PowerShell and Multi Factor Authentication enabled!
Azure Active Directory
Once you have the Azure Active Directory module installed, connecting with Multi Factor Authentication is done by specifying the AccountId parameter, and not a full credential object as we would do with single factor authentication. This will Open up a window, asking you to enter the password for that account, and then your second authentication method as seen below.
Connect-AzureAD -AccountId jeff.collins@globomantics.org
SharePoint Online
When we connect to SharePoint Online using PowerShell, we use the Connect-SPOService cmdlet as usual as well as the URL parameter, which is the URL of your SharePoint Online Admin Center, and simply skip specifying the -Credentials parameter. This will open a pop-up window asking for our credentials, as well as the second method of Authentication as you can see below!
Connect-SPOService -Url https://<SP Admin Center>.sharepoint.com
Exchange Online
While the previous two were easy, this one is a bit more complicated since we need to download a module, whereas to connect with Single Factor Authentication there is nothing to download! From the Exchange Online Admin Center, go to the Hybrid section, and click on Configure under the Exchange Online PowerShell module.
You need to do this with Internet Explorer, or else you will be getting a beautiful “Application Cannot Be Started” error as we talked about in this blog! Exchange Online PowerShell Module Error: Application Cannot be Started – Contact the Application Vendor
Once you have the Exchange Online Module, you need to use the Connect-EXOPSSession PowerShell cmdlet, and specify the user account that you will be connecting with.
Connect-EXOPSSession -UserPrincipalName jeff.collins@globomantics.org
If you are in Office 365 Germany, you need to provide a few more parameters, as seen in the following example.
Connect-EXOPSSession ` -UserPrincipalName jeff.collins@globomantics.org ` -ConnectionUri https://outlook.office.de/PowerShell-LiveID ` -AzureADAuthorizationEndPointUri https://login.microsoftonline.de/common
Office 365 Security and Compliance Center
To connect to the Office 365 Security and Compliance Center with Multi Factor Authentication, you need the same PowerShell module as Exchange Online, about which we talked earlier, but you will be using the Connect-IPPSSession PowerShell cmdlet as seen in the following example.
Connect-IPPSSession -UserPrincipalName jeff.collins@globomantics.org
If you are part of Office 365 Germany, you will need to provide the additional parameters seen below.
Connect-IPPSSession ` -UserPrincipalName jeff.collins@globomantics.org ` -ConnectionUri https://ps.compliance.protection.outlook.de/PowerShell-LiveID ` -AzureADAuthorizationEndPointUri https://login.microsoftonline.de/common
Skype for Business
To connect to Skype for Business Online using Multi Factor Authentication , you need to use the New-CSOnlineSession PowerShell cmdlet
$Session = New-CsOnlineSession -UserName jeff.collins@globomantics.org Import-PSSession $Session
Microsoft Teams
To Connect to Microsoft Teams, you use the Connect-MicrosoftTeams PowerShell cmdlet, and specify the -AccountID parameter. Similar to the other services, you will get a prompt asking you to input your password, and second method of authentication.
Connect-MicrosoftTeams -AccountId jeff.collins@globomantics.org
That is it, we have now looked at how to connect to all Office 365 Services, using PowerShell and Multi Factor Authentication!
Leave a comment and don’t forget to like the Vlad Talks Tech Page on Facebook and to follow me on Twitter here for the latest news and technical articles on SharePoint. I am also a Pluralsight author, and you can view all the courses I created on my author page. |