Chat with us, powered by LiveChat

Blog

Back

Connecting to Office 365 using PowerShell through a Web Proxy Server

13 Jun 2013 by Emma Robinson

This is a follow up to blog post we previously wrote showing how to connect to Office 365 using PowerShell.
I recently came across a scenario where a company routed all traffic through a web proxy server – which is not uncommon at large organisations.
I had to make some modifications to my Office 365 connection strings and tell it to use the same settings as my Internet Explorer proxy settings.
First, I had to use the New-PSSessionOption cmdlet to save add the proxy information like this:

$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig

I then had to pass the $proxysettings variable to the new session creation as follows:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection -SessionOption $proxysettings

When you put it all together, it looks like this:

PS C:\Users\burns_000\Desktop> $proxysettings = New-PSSessionOption -ProxyAccessType IEConfig
PS C:\Users\burns_000\Desktop> $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection -SessionOption $proxysettings
WARNING: Your connection has been redirected to the following URI:
"https://pod51048psh.outlook.com/powershell-liveid?PSVersion=3.0 "

PS C:\Users\burns_000\Desktop> Import-PSSession $session
PS C:\Users\burns_000\Desktop>