#requires -version 2.0 # ----------------------------------------------------------------------------- # Script: Get-QOTD.ps1 # Author: Jeffery Hicks # http://jdhitsolutions.com/blog # follow on Twitter: http://twitter.com/JeffHicks # Date: 11/5/2010 # Version: 1.0 # Keywords: RSS, XML, WebClient # Comments: # # "Those who neglect to script are doomed to repeat their work." # # **************************************************************** # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * # **************************************************************** # ----------------------------------------------------------------------------- Function Get-QOTD { [cmdletBinding()] Param() Write-Verbose "Starting Get-QOTD" #create the webclient object $webclient = New-Object System.Net.WebClient #define the url to connect to $url="http://feeds.feedburner.com/brainyquote/QUOTEBR" Write-Verbose "Connecting to $url" Try { #retrieve the url and save results to an XML document [xml]$data =$webclient.downloadstring($url) #parse out the XML document to get the first item which #will be the most recent quote $quote=$data.rss.channel.item[0] } Catch { $msg="There was an error connecting to $url" $msg+=$_.Exception.Message Write-Warning $msg } if ($quote) { Write-Verbose $quote.OrigLink "{0} - {1}" -f $quote.Description,$quote.Title } else { Write-Warning "Failed to get data from $url" } Write-Verbose "Ending Get-QOTD" } #end function #OPTIONAL: create an alias #Set-Alias -name "qotd" -Value Get-QOTD