Skip to content

/errors/exchange-online/connecting-to-remote-server-access-denied

Connecting to remote server outlook.office365.com failed with the following error message : Access is denied

The commands on this page have not been executed by our verification runner yet.updated
tool
Exchange Online PowerShell
versions
Exchange Online, ExchangeOnlineManagement 3.x
os
windows

New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : Access is denied. comes from the old way of managing Exchange Online: a WinRM remote PowerShell session opened with Basic authentication. Microsoft retired Basic authentication in Exchange Online, and since October 2023 Exchange Online PowerShell uses REST API connections instead of remote PowerShell. Such scripts cannot be fixed with a different password; replace the connection code.

Old code that produces the error:

powershell
$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/PowerShell-LiveID/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session

Current code:

powershell
Install-Module ExchangeOnlineManagement -Scope CurrentUser   # once
Connect-ExchangeOnline -UserPrincipalName admin@contoso.com

The cmdlet names after connecting are the same (Get-Mailbox, Set-Mailbox, ...), so the rest of the script usually runs unchanged.

The same old connection code fails in other ways, depending on the client configuration:

  • WinRM refuses Basic authentication on the client (The WinRM client cannot process the request. Basic authentication is currently disabled in the client configuration.). Do not re-enable it: the REST-based module does not need it.
  • Connect-ExchangeOnline -UseRPSSession in recent module versions: the switch is deprecated (module 3.9.2 and later) because remote PowerShell connections were replaced.

Unattended scripts

Scripts that stored a user name and password for Basic authentication should move to app-only authentication with a certificate. See Connect-ExchangeOnline with a certificate. On a computer without a browser you can also sign in interactively with the device code flow in PowerShell 7.

Sources