Connect Azure AD and all Microsft 365 Services from PowerShell

Connect Azure AD and all Microsft 365 Services from PowerShell

2020, May 14    

Pre-requisites


Using a Password

$credential = Get-Credential

Azure Active Directory PowerShell for Graph Module

Connect-AzureAD -Credential $credential

Azure Active Directory Module for Windows PowerShell

Connect-MsolService -Credential $credential

SharePoint Online

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://<domainhost>-admin.sharepoint.com -credential $credential

Skype for Business Online

Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession

Exchange Online

Connect-ExchangeOnline -Credential $credential -ShowProgress $true

Teams

Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

Microsoft 365 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

Close Down all connected sessions

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

AzureAD and all Microsoft365 from Azure Active Directory PowerShell for Graph module

$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
$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
Connect-ExchangeOnline -Credential $credential -ShowProgress $true
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

AzureAD and all Microsoft365 from Azure Active Directory Module for Windows PowerShell module

$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
$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
Connect-ExchangeOnline -Credential $credential -ShowProgress $true
Import-Module MicrosoftTeams
Connect-MicrosoftTeams -Credential $credential

Using Modern Authentication (MFA)

Single block to connect to Azure AD, SharePoint Online, Skype for Business, Exchange Online, and Teams

$acctName="<UPN of the account, such as belindan@litwareinc.onmicrosoft.com>"
$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"

Azure Active Directory PowerShell for Graph Module

Connect-AzureAD

Azure Active Directory Module for Windows PowerShell

Connect-MsolService

SharePoint Online

Connect-SPOService -Url https://$orgName-admin.sharepoint.com

Skype for Business Online

$sfboSession = New-CsOnlineSession -UserName $acctName
Import-PSSession $sfboSession

Exchange Online

Connect-ExchangeOnline -UserPrincipalName $acctName -ShowProgress $true

Teams

Import-Module MicrosoftTeams
Connect-MicrosoftTeams

AzureAD and all Microsoft365 from Azure Active Directory PowerShell for Graph module

$acctName="<UPN of the account, such as belindan@litwareinc.onmicrosoft.com>"
$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
#Exchange Online
Connect-ExchangeOnline -UserPrincipalName $acctName -ShowProgress $true
#Teams
Import-Module MicrosoftTeams
Connect-MicrosoftTeams

AzureAD and all Microsoft365 from Azure Active Directory Module for Windows PowerShell module

$acctName="<UPN of the account, such as belindan@litwareinc.onmicrosoft.com>"
$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
#Exchange Online
Connect-ExchangeOnline -UserPrincipalName $acctName -ShowProgress $true
#Teams
Import-Module MicrosoftTeams
Connect-MicrosoftTeams

Note > To connect to Security & Compliance Center with Modern Authentication (MFA), you need to open Exchange Online console, then hit below buttom Security & Compliance Center with MFA

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