Working with remote Powershell behind a proxy server

PowerShell

PowerShell

This week, I have been working on an application that generates new users in Active Directory. Part of the application generates an Office 365 account for the user using a programmatically-generated PowerShell script.

Everything worked fine during testing, however once we put it into production, the script failed. Manually running the script on the server revealed that the script failed to connect to the remote PowerShell session.

Unfortunately, whitelisting the server to bypass the proxy server failed. After spending weeks on the issue, I gave up and resigned myself to running the application on my machine.

This week, I decided to take another crack at it.

My Google-fu turned up a blog post from Fabrice Zerrouki, describing how to configure the proxy server in PowerShell.

First, enter the command  netsh winhttp import proxy source=ie This will work in PowerShell and the standard Command Prompt.

For authentication purposes, you’ll also need the following code:

After running these commands, the script worked perfectly! I tested the script again after we rebooted the server, and all is working.

Leave a Reply

Your email address will not be published. Required fields are marked *