Friday Fun: Quote of the Day Revised

talkbubble-v3This week TrainSignal has been running a contest to celebrate my new PowerShell 3.0 course . All you have to do to win is enter some off-the-wall, silly or non-production use of PowerShell. I’ve posted a few examples on the TrainSignal blog this week.  These Friday Fun posts I write also follow the same idea. Although, I do have a sneaky intention of teaching you  something about PowerShell without you realizing it.

For a while now I’ve been using a function to  get the latest quote of the day from Brainyquotes. When I first wrote the function I had to resort to .NET and the webclient class. But now with PowerShell 3.0, we have new web cmdlets that are even easier to use so I decided to rewrite my function.

The function is downloading XML content from an RSS feed. I’ve found that using Invoke-RestMethod is a handy cmdlet for this task because it formats the data into an easy to use object. All my function does is write a string composed of different properties of the most current entry. My first post this week on the TrainSignal blog uses some of this same code.

Ok. Maybe you don’t need daily inspiration but now you’ve seen another example of Invoke-Restmethod in action and maybe that is something you need. Enjoy and have fun out there.

6 thoughts on “Friday Fun: Quote of the Day Revised”

  1. Your function looks great.

    I used below 1 liner in my PS2 scripts.

    ([xml]((new-object System.Net.WebClient).DownloadString(“”))).GetElementsByTagName(“item”).Item(1).description

    1. I don’t doubt that it works. My belief is that if I’m putting something like that into a function, I only have to write the function once so I might as well make it easy to follow. Sure, you can build a function with a long one-liner like that, but if someone else had to troubleshoot or debug it, it would be much harder. Just my opinion. In any event, thank you for your interest and taking the time to post a comment.

Comments are closed.