Home > Powershell > Powershell behind a Proxy server

Powershell behind a Proxy server

so there I was, living in my Powershell session, when I stumbled across a cmdlet that looked kinda useful.
I wanted a little more info, but when I ran “get-help ” – I discovered that my local help files were out of date.

That’s easy to fix -no?:

Update-Help : Failed to update Help for the module(s) 'Microsoft.PowerShell.Management, Microsoft.PowerShell.Security,
Microsoft.PowerShell.Utility, CimCmdlets, ISE, Microsoft.PowerShell.Diagnostics, Microsoft.PowerShell.Host, Microsoft.WSMan.Management,
PSDesiredStateConfiguration, PSScheduledJob, PSWorkflow, PSWorkflowUtility, Microsoft.PowerShell.Core' with UI culture(s) {en-US} : Unable
to connect to Help content. The server on which Help content is stored might not be available. Verify that the server is available, or
wait until the server is back online, and then try the command again.
At line:1 char:1
+ update-help
+ ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToConnect,Microsoft.PowerShell.Commands.UpdateHelpCommand

errr . . .no!

Of course, I was in the office – behind a corporate proxy, that needed authentication . . and I needed my Powershell session to use my corporate proxy.

As it goes, the ie proxy settings are managed by GPO, so I figured I’d just use these.

First step – let’s check what our Powershell environment is using for its proxy:

netsh winhttp show proxy

Current WinHTTP proxy settings:

    Direct access (no proxy server).

hmm – not great, let’s change it

netsh winhttp import proxy source=ie
netsh winhttp show proxy

cool – we have now told Powershell to use our ie proxy.
Now, in our environment, we need to authenticate against the proxy.

If you manually authenticate (Username, Password) take this approach:

$webclient=New-Object System.Net.WebClient

Alternatively, if you are in a Domain environment and your proxy accepts NTLM/AD Auth, here’s what to do:

$webClient = new-object System.Net.WebClient
$webClient.Headers.Add(“user-agent”, “PowerShell Script”)
$webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials


Now all that’s left to do is run


And try remember what it was that you were trying to achieve in the first place.

Categories: Powershell Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.