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
$wc
}

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

$webclient = Get-WebClient
[xml]$powershelltips = $webClient.DownloadString(
'http://powershell.com/cs/blogs/tips/rss.aspx')
$powershelltips.rss.channel.item | Select-Object title, link

Twitter This Tip!
ReTweet this Tip!