Board logo

标题: [转载代码] [PowerShell每日技巧]从YouTube上搜索、查看PowerShell视频(20131225) [打印本页]

作者: DAIC    时间: 2014-1-1 11:38     标题: [PowerShell每日技巧]从YouTube上搜索、查看PowerShell视频(20131225)

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!
  1. $keyword = "Learn PowerShell"
  2. Invoke-RestMethod -Uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=$($keyword.Replace(' ','+'))" |
  3. Select-Object -Property Title, @{N='Author';E={$_.Author.Name}}, @{N='Link';E={$_.Content.src}}, @{N='Updated';E={[DateTime]$_.Updated}} |
  4. Sort-Object -Property Updated -Descending |
  5. Out-GridView -Title "Select your '$Keyword' video, then click OK to view." -PassThru |
  6. 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.

http://powershell.com/cs/blogs/tips/archive/2013/12/25/search-and-view-powershell-videos.aspx




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2