Exchange Online Implicit Remoting with Azure Automation Hybrid Runbook Workers

When using implicit remoting to connect to Exchange Online we would typically run the following command.

$O365Credential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $O365Credential -Authentication Basic -AllowRedirection

Import-PSSession $Session -DisableNameChecking

However when running this within a PowerShell runbook on an Azure Hybrid Runbook worker you may see errors trying to execute certain commands. This is due to remoting to a constrained endpoint.

Run the following instead to be able to connect and use all the cmdlets without any errors.

$O365Credential = Get-Credential

$ExchangeSession=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $O365Credential -Authentication Basic -AllowRedirection

Import-Module (Import-PSSession -Session $ExchangeSession -AllowClobber -DisableNameChecking) -Global

Share on facebook
Facebook
Share on linkedin
LinkedIn
Share on twitter
Twitter

Leave a Reply