Connecting to Exchange Online
Connecting to Exchange Online involves creating a remote PowerShell session. This session is created using a special URL that points to your tenant. When you import the session, it downloads all the commands that the remote Exchange server understands.
You do not need to connect to Office 365 using Connect-MsolService
before connecting to Exchange Online. Note that if you run the following scripts without setting $Credentials
first, it will prompt you for authentication before connecting:
$TenantName = "my365tenant" $exchUri = "https://ps.outlook.com/PowerShell-LiveID" if (-not [string]::IsNullOrEmpty($TenantName)) { if (-not $TenantName.EndsWith('onmicrosoft.com')) { $TenantName = "$TenantName.onmicrosoft.com" } $exchUri = "$($exchUri)?DelegatedOrg=$($TenantName)" } Write-Host -ForegroundColor Cyan "Connect to Exchange Online" Write-Host "Uri: $exchUri " $global:ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchUri...