Skip to Content

Connect PowerShell to O365

28 July 2026 by
stuart@stuclark.uk

To connect Powershell to Office365 (with MSOnline module and ExhangeOnline modules loaded - run on an on-prem Exchange server for full benefits)

((Powershell 5.1 or better needed!)
Set-ExecutionPolicy Unrestricted
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication  Basic -AllowRedirection
Import-PSSession $Session
Import-Module MSOnline
Connect-MsolService
in News
Get all instances of O365 "user@domain.com"