Powershell: Connect to Azure Active Directory and Microsoft O365

Use the following Powershell script to connect to Azure Active Directory and Microsoft O365. This enables you to use all the O365 Powershell commands.

#Connecting to Exchange Online and Azure Active Directory

#This first command will import the Azure Active Directory module into your PowerShell session.
Import-Module MSOnline

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

#Establishes Online Services connection to Azure Active Directory  
Connect-MsolService -Credential $credential

#Creates an Exchange Online session
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $credential -Authentication Basic -AllowRedirection

#Import session commands
Import-PSSession $ExchangeSession

 

image

(Download the Powershell plugin here)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.