Search and View PowerShell Videos

by Dec 25, 2013

PowerShell is amazing. It will let you search YouTube videos for keywords you select, then offer the videos to you, and upon selection play the videos as well.

Here's a little script that–Internet access assumed–lists the most recent "Learn PowerShell" videos from YouTube. The list opens in a grid view window, so you can use the full text search at the top or sort columns until you find the video you want to give a try.

Next, click the video to select it, and then click "OK" in the lower-right corner of the grid.

PowerShell will launch your web browser and play the video. Awesome!

$keyword = "Learn PowerShell"

Invoke-RestMethod -Uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=$($keyword.Replace(' ','+'))" | 
Select-Object -Property Title, @{N='Author'={$_.Author.Name}}, @{N='Link'={$_.Content.src}}, @{N='Updated'={[DateTime]$_.Updated}} |
Sort-Object -Property Updated -Descending |
Out-GridView -Title "Select your '$Keyword' video, then click OK to view." -PassThru |
ForEach-Object { Start-Process $_.Link } 

Simply change the variable $keyword in the first line to search for different videos or topics.

Note that due to a bug in PowerShell 3.0, Invoke-RestMethod will only return half of the results. In PowerShell 4.0, this bug was fixed.

Twitter This Tip! ReTweet this Tip!