Connect Azure AD and all Microsoft 365 Services from PowerShell
Pre-requisites
- Your account must be member of the corresponding Microsoft 365 admin role you’re going to administer.
- Your computer must use 64-bit version of latest Windows releases, at a minimum:
- Windows 7 SP1 (with .NET Framework 4.5.x and 3.0 or 4.0)
- Windows Server 2008 R2 SP1 (with .NET Framework 4.5.x and 3.0 or 4.0)
- Have installed following Modules
- Allow running signed scripts in your system
Set-ExecutionPolicy RemoteSigned
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