Microsoft 365 — Connecting via PowerShell
To open a PowerShell session with Office 365:
- Run PowerShell.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCred -Authentication Basic -AllowRedirection
- Enter the Global Administrator credentials when prompted.
Import-PSSession $Session -DisableNameChecking
- Enter the desired commands.
- When finished, enter:
You can enter as many commands as required within a session, and leave a session running for a long time. If PowerShell is closed without removing the session, the session will expire by itself anyway. However, this may prevent further logins if too many sessions are left open.