Microsoft 365 — Connecting via PowerShellExchange OnlineTo open a PowerShell session with Exchange Online in Office 365: - Run PowerShell.
- Enter:
$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.
- Enter:
Import-PSSession $Session -DisableNameChecking - Enter the desired commands.
- When finished, enter:
Remove-PSSession $Session
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. To enter the credentials from the PowerShell command-line, first enter: $UserCred=New-Object System.Management.Automation.PSCredential -ArgumentList 'username', (ConvertTo-SecureString -AsPlainText 'password' -Force) AzureTo connect to services within Azure: Import-Module -Name AzureAD -Scope Local;$UserCred=New-Object System.Management.Automation.PSCredential -ArgumentList 'username', (ConvertTo-SecureString -AsPlainText 'password' -Force) Connect-AzureAD -Credential $UserCred; <command> |