Connect to Azure AD/Office 365 via PowerShell

The Problem

The majority of tasks to do with Office 365 can be accomplished via the GUI, however there are often situations where you need to connect via PowerShell to toggle certain features. Connect to Azure AD/Office 365 via PowerShell.

The Fix

To connect to Office 365 via PowerShell, you will need:

Once installed, run the Azure AD PowerShell app and run the following:

  1. $UserCredential = Get-Credential
    1. Type the admin credentials for Office 365
  2. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
  3. Import-PSSession $Session

You are now connected to Office 365 via PowerShell! Go and run your commands!