18 August 2017

PowerShell behind Authenticating proxy



I've seen this at my work a few to many times.
Certain command's just don't get through or something errors out with strange unidentifiable reasons.

Not all command in PowerShell will go through the proxy, IE will pass this on using Windows Integrated Authentication but the .NET Webclient used by PowerShell doesn't appear to do this.

How to get past this? Copy/paste this in your PowerShell windows and all your commands go through your proxy.

$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString('http://microsoft.com')

You could add this to your profile to load at startup:

New-item –type file –force $profile            
Notepad $profile

Paste in Notepad:

$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString('http://microsoft.com')

Save the Notepad Microsoft.PowerShellISE_profile.ps1 file

There is a request on Connect to have this looked at by the PowerShell team.
https://connect.microsoft.com/PowerShell/feedback/details/754102/a-cmdlet-to-create-a-proxy-configuration-settings-object

No comments:

Post a Comment