Use Internet Connection with Default Proxy

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

If you want PowerShell to use the same proxy settings that are set in your Internet Explorer browser, then here's the code you need:

$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
$proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$web = New-Object System.Net.WebClient
$web.proxy = $proxy
$web.UseDefaultCredentials = $true

Once set up, you can then use the $web object to download web site content or even files:

$url = 'http://www.powershell.com'
$web.DownloadString($url)

Twitter This Tip! ReTweet this Tip!


Posted Apr 13 2012, 06:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.