Get WebClient with Proxy Authentication

by Nov 12, 2010

If your company is using an Internet proxy, and you'd like to access Internet with a webclient object, make sure it uses the proxy and supplies your default credentials to it. You could write a little helper function to get such a pre-configured webclient:

function Get-Webclient {
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$wc.Proxy.Credentials = $wc.Credentials

Next, you could retrieve an RSS feed from the Internet. For example:

$webclient = Get-WebClient
[xml]$powershelltips = $webClient.DownloadString(
$ | Select-Object title, link

Twitter This Tip!
ReTweet this Tip!