Connect PowerShell to Office 365 through Proxy

Working with powershell to manage office 365 is one of the regular job for every Office 365 Admin. This is a follow up post to Connect Office 365 using Remote PowerShell through proxy.
 

You can use the below command to connect Office 365 using remote powershell:

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

The above command will work fine when you connect internet without proxy server, but you will receive the following error when connect via proxy.

[ps.outlook.com] Connecting to remote server failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

To overcome this problem, we need to use proxy setting options in New-PSSession command. To set the proxy options, use the following procedure:

1. Use the ProxyAccessType, ProxyAuthentication, and ProxyCredential parameters of the New-PSSessionOption cmdlet to create a session option object with the proxy settings for your enterprise. Save the option object is a variable.

2. Use the variable that contains the option object as the value of the SessionOption parameter of a New-PSSession command.

$365Logon = Get-Credential
$proxyOptions = New-PSSessionOption -ProxyAccessType IEConfig
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection -SessionOption $proxyOptions
Import-PSSession $Session

If you want to connect Office 365 through Outbound Internet Authenticating Proxy, you have to add addtional parameter -ProxyAuthentication in New-PSSessionOption cmdlet.

$proxyOptions = New-PSSessionOption -ProxyAccessType IEConfig -ProxyAuthentication basic;

For more detailed information: please refer to the HOW TO CONFIGURE REMOTING WITH A PROXY SERVER section in the following article:
http://technet.microsoft.com/en-us/library/dd347642.aspx


Advertisement

1 thought on “Connect PowerShell to Office 365 through Proxy”

Leave a Comment