Connect to Office 365 Cloud Services using PowerShell

Scenario description

To get connected with your Office 365 service, you must first import the relevant modules and then create the related remote sessions. In this scenario, we are importing the Azure Active Directory, SharePoint Online, and Skype for Business Online modules and then establishing a connection to them including Exchange Online.

Note: Exchange Online does not require you to import a module.

Once you have run the scripts, you will be connected to the above Office 365 services.

Connect to Office 365 Cloud Services using PowerShell

Capture administrative credential for future connections.
$credential = get-credential

Imports the installed Azure Active Directory module.

Import-Module MSOnline

Establishes Online Services connection to Azure Active Directory.

Connect-MsolService -Credential $credential
Imports the installed Skype for Business Online services module.
Import-Module LyncOnlineConnector
Create a Skype for Business Powershell session using defined credential.
$lyncSession = New-CsOnlineSession -Credential $credential
Imports Skype for Business session commands into your local Windows PowerShell session.
Import-PSSession $lyncSession
Imports SharePoint Online session commands into your local Windows PowerShell session.
Import-Module Microsoft.Online.Sharepoint.PowerShell
This connects you to your SharePoint Online services. Substitute the ‘contoso’ portion of the URL with the name of your SharePoint Online tenant.
Connect-SPOService -url https://contoso-admin.sharepoint.com -Credential $credential
Creates an Exchange Online session using defined credential.
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection

This imports the Office 365 session into your active Shell.

Import-PSSession $ExchangeSession
Resources
Using Windows PowerShell to manage Office 365.

Connect to Office 365 by using a single Windows PowerShell window.

Comments