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:
1 2 3 4 5 6 |
# Create the object $webclient=New-Object System.Net.WebClient # Provide the username and password for the proxy $creds=Get-Credential # And then apply those credentials to Powershell $webclient.Proxy.Credentials=$creds |
After running these commands, the script worked perfectly! I tested the script again after we rebooted the server, and all is working.