Connect to all Office 365 services in a single Windows PowerShell window

When you use PowerShell to manage Office 365, it is possible to have up to five different Windows PowerShell sessions open at the same time corresponding to Microsoft 365 admin center, SharePoint Online, Exchange Online, Skype for Business Online, Microsoft Teams, and the Security & Compliance Center. With five different connection methods in separate Windows PowerShell sessions, your desktop could look like this:

This is not optimal for managing Office 365 because you can’t exchange data among those five windows for cross-service management. This topic describes how to use a single instance of Windows PowerShell from which you can manage Office 365, Skype for Business Online, Exchange Online, SharePoint Online, Microsoft Teams, and the Security & Compliance Center.

Note

This article currently only contains the commands to connect to the Office 365 Worldwide (+GCC) cloud. Additional notes provide links to articles with information about connecting to the other Office 365 clouds.

Before you begin

Before you can manage all of Office 365 from a single instance of Windows PowerShell, consider the following prerequisites:

  • The Office 365 work or school account that you use for these procedures needs to be a member of an Office 365 admin role. For more information, see About Office 365 admin roles. This a requirement for Office 365 PowerShell, not necessarily for all other Office 365 services.
  • You can use the following 64-bit versions of Windows:
    • Windows 10
    • Windows 8.1 or Windows 8
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2 or Windows Server 2012
    • Windows 7 Service Pack 1 (SP1)*
    • Windows Server 2008 R2 SP1*

      * You need to install the Microsoft .NET Framework 4.5.x and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0. For more information, see Installing the .NET Framework and Windows Management Framework 3.0 or Windows Management Framework 4.0.

      You need to use a 64-bit version of Windows because of the requirements for the Skype for Business Online module and one of the Office 365 modules.

  • You need to install the modules that are required for Azure AD, SharePoint Online, Skype for Business Online and Teams:
  • Windows PowerShell needs to be configured to run signed scripts for Skype for Business Online, Exchange Online, Microsoft Teams, and the Security & Compliance Center. To do this, run the following command in an elevated Windows PowerShell session (a Windows PowerShell window you open by selecting Run as administrator).
PowerShell

Set-ExecutionPolicy RemoteSigned

Connection steps when using a password

Here are the steps to connect to all the services in a single PowerShell window.

  1. Open Windows PowerShell as an administrator (use Run as administrator).
  2. Run this command, and enter your Office 365 work or school account credentials.
PowerShell

$credential = Get-Credential
  1. Run this command to connect to Azure Active Directory (AD) using the Azure Active Directory PowerShell for Graph module.
PowerShell

Connect-AzureAD -Credential $credential

Alternately, if you are using the Microsoft Azure Active Directory Module for Windows PowerShell module, run this command.

PowerShell

Connect-MsolService -Credential $credential

Note

PowerShell Core does not support the Microsoft Azure Active Directory Module for Windows PowerShell module and cmdlets with Msol in their name. To continue using these cmdlets, you must run them from Windows PowerShell.

  1. Run these commands to connect to SharePoint Online. Replace <domainhost> with the actual value for your domain. For example, for “litwareinc.onmicrosoft.com”, the <domainhost> value is “litwareinc”.
PowerShell

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://<domainhost>-admin.sharepoint.com -credential $credential
  1. Run these commands to connect to Skype for Business Online. A warning about increasing the WSMan NetworkDelayms value is expected the first time you connect and should be ignored.
PowerShell

Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession
  1. Run these commands to connect to Exchange Online.
PowerShell

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking

Note

To connect to Exchange Online for Office 365 clouds other than Worldwide, see Connect to Exchange Online PowerShell.

  1. Run these commands to connect to Teams PowerShell.
PowerShell

Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

Note

To connect to Microsoft Teams clouds other than Worldwide, see Connect-MicrosoftTeams.

  1. Run these commands to connect to the Security & Compliance Center.
PowerShell

$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc

Note

To connect to the Security & Compliance Center for Office 365 clouds other than Worldwide, see Connect to Office 365 Security & Compliance Center PowerShell.

Here are all the commands in a single block when using the Azure Active Directory PowerShell for Graph module. Specify the name of your domain host, and then run them all at one time.

PowerShell

$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
$credential = Get-Credential
Connect-AzureAD -Credential $credential
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -credential $credential
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

Alternately, here are all the commands in a single block when using the Microsoft Azure Active Directory Module for Windows PowerShell module. Specify the name of your domain host, and then run them all at one time.

PowerShell

$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
$credential = Get-Credential
Connect-MsolService -Credential $credential
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -credential $credential
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

When you are ready to close down the Windows PowerShell window, run this command to remove the active sessions to Skype for Business Online, Exchange Online, SharePoint Online, and the Security & Compliance Center:

PowerShell

Remove-PSSession $sfboSession ; Remove-PSSession $exchangeSession ; Remove-PSSession $SccSession ; Disconnect-SPOService ; Disconnect-MicrosoftTeams 

Connection steps when using multi-factor authentication

Here are all the commands in a single block to connect to Azure AD, SharePoint Online, and Skype for Buiness using multi-factor authentication in a single window using the Azure Active Directory PowerShell for Graph module. Specify the user principal name (UPN) name of a user account and your domain host name, and then run them all at one time.

PowerShell

$acctName="<UPN of the account, such as [email protected]>"
$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
#Azure Active Directory
Connect-AzureAD
#SharePoint Online
Connect-SPOService -Url https://$orgName-admin.sharepoint.com
#Skype for Business Online
$sfboSession = New-CsOnlineSession -UserName $acctName
Import-PSSession $sfboSession
Import-Module MicrosoftTeams
Connect-MicrosoftTeams

Alternately, here are all the commands when using the Microsoft Azure Active Directory Module for Windows PowerShell module.

PowerShell

$acctName="<UPN of the account, such as [email protected]>"
$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
#Azure Active Directory
Connect-MsolService
#SharePoint Online
Connect-SPOService -Url https://$orgName-admin.sharepoint.com
#Skype for Business Online
$sfboSession = New-CsOnlineSession -UserName $acctName
Import-PSSession $sfboSession
Import-Module MicrosoftTeams
Connect-MicrosoftTeams

For Exchange Online and the Security & Compliance Center, see the following topics to connect using multi-factor authentication:

Note that in both cases, you must connect using separate sessions of the Exchange Online Remote PowerShell Module.

Archives
Don`t copy text!