.net / rss / web client

PowerShell offers an intriguing option for getting Web content to a PowerShell session. By using a combination of the .NET Web client object and PowerShell's native support for XML, it is a snap to pull data from a Web site and display it in a PowerShell console. As an example, the following script queries Microsoft's basic RSS feed for security bulletins and displays bulletin information in a color coded console:

#GetSecurityRSS.ps1
#Query Microsoft's Basic Security Feed for latest bulletins
#Critical bulletins will be displayed in Red
#Important bulletins will be display in Yellow
#Everything else will be displayed in Green

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Web")
$webclient = new-object System.Net.WebClient
$url="http://www.microsoft.com/technet/security/bulletin/secrss.aspx"
## Get the web page into a single string
$data =[xml]$webclient.downloadstring($url)

if ($data -ne $Null) {
Write-Host -backgroundcolor Yellow -foregroundcolor blue `
$data.rss.channel.Title
Write-Host "Last Updated" $data.rss.channel.LastBuildDate `n
$i=0
do {
write-Host -foregroundcolor White `
$data.rss.channel.item[$i].Title
#color code description based on severity
if ($data.rss.channel.item[$i].Description `
-Like "*Rating:Critical*") {
$color="Red"
}
elseif ($data.rss.channel.item[$i].Description `
-Like "*Rating:Important*"){
$color="Yellow"
}
else {
$color="Green"
}
Write-Host -foregroundcolor $color `
$data.rss.channel.item[$i].Description `n
$i++
}
until ($i -gt ($data.rss.channel.item).count)
}
else {
Write-Host -foregroundcolor Red "Could not get " $url
}