Connect to multiple Office 365 services in a one PowerShell window

Balu Ilag | Feb 11th, 2020

Connect to multiple Office 365 services in a one PowerShell window

Connect to multiple Office 365 services in a one PowerShell window

As an admin you always dealing with managing the Office 365 services using Office 365 Admin Center and individual admin center such Azure Active Directory, Microsoft Teams admin center, Exchange admin center, SharePoint admin center and so on. However, when you want to add, customize new settings that not available through admin center GUI then the only option left is to use windows PowerShell with individual modules. But if you require to connect one PowerShell model to modify one setting and then connect another PowerShell to make changes on another application. For example, when you want to create and assign custom emergency call (e.g. 911) routing policy for Microsoft Teams, then you first connect to the Azure Active Directory PowerShell for Graph module and the connect Skype for Business PowerShell online module to assign the policy.

If you come across such situation then this article will help you to connect to all Office 365 services in a one PowerShell window.

It is possible to connecting 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, and the Security & Compliance Center, using five different connection methods in separate Windows PowerShell sessions, however your desktop could look messy.

Let’s see how we can optimally solve PowerShell connection problem without make desktop messy.

First understand the prerequisite for managing all of Office 365 from a single instance of Windows PowerShell:

  1. You need an Office 365 work or school account that you use for these procedures needs to be a member of an Office 365 admin role, for example Teams service admin, Global Admin etc.
  2. Next thing is your Operating system (64 bit) must be one of the below:
    1. Windows 10
    2. Windows 8.1 or Windows 8
    3. Windows Server 2019
    4. Windows Server 2016
    5. Windows Server 2012 R2 or Windows Server 2012
    6. Windows 7 SP1 and Windows Server 2008 SP1 with 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.
  3. Then you need to install the PowerShell modules that are required for Azure AD, SharePoint Online, and Skype for Business Online (Microsoft Teams):
    1. Azure Active Directory V2
    2. SharePoint Online Management Shell
    3. Skype for Business Online, Windows PowerShell Module
  4. Another important prerequisite is Windows PowerShell needs to be configured to run signed scripts for Skype for Business Online, Exchange Online, and the Security & Compliance Center. In order to do this, run the following command in an elevated Windows PowerShell session (a Windows PowerShell window you open by selecting Run as administrator).

Set-ExecutionPolicy RemoteSigned

 

After completing the prerequisite, you now connect PowerShell using your login credential. Follow the below steps to connect to all the services in a single PowerShell window.

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

$credential = Get-Credential

  1. Run below command to connect to Azure Active Directory (AD) using the Azure Active Directory PowerShell for Graph module.

Connect-AzureAD -Credential $credential

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

Connect-MsolService -Credential $credential

Note: PowerShell Core does not support the Microsoft Azure Active Directory Module for Windows PowerShell module and command with Msol in their name. To continue using this command, 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 “bloguc.onmicrosoft.com”, the <domainhost> value is “bloguc”.

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.

Import-Module SkypeOnlineConnector

$sfboSession = New-CsOnlineSession -Credential $credential

Import-PSSession $sfboSession

  1. Run these commands to connect to Exchange Online.

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

Import-PSSession $exchangeSession -DisableNameChecking

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

$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

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.

$orgName=”<for example, bloguc for bloguc.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

Refer the below screenshot.

OR, 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.

 

$orgName=”<for example bloguc for bloguc.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

 

How do I single PowerShell Windows using multi-factor authentication?

If you are using MFA (Multi-Factor Authentication) then here are all the commands in a single block to connect to Azure AD, SharePoint Online, and Skype for Business 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.

$acctName=”<UPN of the account, such as bilag@bloguc.onmicrosoft.com>”

$orgName=”<for example, bloguc for bloguc.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

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

$acctName=”<UPN of the account, such as bilag@bloguc.onmicrosoft.com>”

$orgName=”<for example, Bloguc for bloguc.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

Thank you.

 

Reference: https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-all-office-365-services-in-a-single-windows-powershell-window

No Comments

Post A Comment