Using PowerShell behind a proxy
Suppose you try to load some resource from the web in PowerShell, e.g., with one of the following two commandlets:
PS> Invoke-WebRequest http://example.org
PS> Update-Help
If you get an “access denied” or “no network connection” error message there may be a web proxy blocking your way, demanding authentication.
What needs to be done? You have to configure PowerShell’s proxy settings. Some commandlets like Invoke-WebRequest
offer options that let you set the proxy for just one command (lines broken for better readability):
PS> Invoke-WebRequest `
>> -Proxy http://proxy.example.net:8080 `
>> -ProxyUseDefaultCredentials `
>> http://example.org
For commandlets that don’t have such options (like Update-Help
), or if you’d rather set the proxy for the whole PowerShell session, issue the following command:
PS> (New-Object System.Net.WebClient).Proxy.Credentials = `
>> [System.Net.CredentialCache]::DefaultNetworkCredentials
All commands after that will implicitly use the system proxy, so you can issue commands like the above Invoke-WebRequest http://example.org
or Update-Help
and they will “just work”.