Quantcast
Viewing all articles
Browse latest Browse all 52

A CmdLet for Channel 9 events (like Ignite)

A while ago, I needed to get my head around PowerShell and building modules again. It was some time ago we were scripting stuff, since we have been spending our time nowadays in Visual Studio and different Web API projects.

I started to browse through the great book “Learn PowerShell Toolmaking in a Month of Lunches” (ISBN: 9781617291166). If you have not read it, I highly recommend you get a hold of a copy!

One thing that is emphasized in the book and something that I agree with is the way you should break down your scripts to modular tools that enables you to “do one thing, and do it well”. Therefore, I needed a small project to accelerate my PS skills. One thing that triggered me was all these Channel 9 download scripts people have been building. I set out to build myself a sustainable solution to be able to aggregate the events and list, sort etc. based on some criteria – A great objective for a “Get” CmdLet.

I actually tried some of the scripts out on the internet, but found that they did not work right off the bat for my purpose.

This one is rather complex but already wrapped with a lot of GUI stuff:
https://gallery.technet.microsoft.com/Channel9-Session-04b2558b

But this one was rather neat and easy to get some ideas from:
https://vniklas.djungeln.se/2015/05/05/downloading-ms-ignite-content-with-powershell-and-bits-from-ch9

It´s rather small and easy to get your head around and edit, which is nice. However, one thing that was puzzling me was some sessions did not download!?

I tried the code myself like this:
$vsessions = Invoke-RestMethod 'http://s.ch9.ms/Events/Ignite/2015/RSS/mp4high'
Then realized that the total amount of sessions was limited: $vsessions.count (the result is 379).
If you were to hit the endpoint with a page set again, you would get even more items in return:
$vsessions2 = Invoke-RestMethod 'http://s.ch9.ms/Events/Ignite/2015/RSS/mp4high?Page=2'
This is yet another 296 sessions! ($vsessions2.Count)

I then check out other events, like TechEd and Build and must say the feeds are rather inconsistent. Like TechEd 2014 in NA for example, this returns 261 items in the first page.

Therefore, I ended up doing some code of my own for my CmdLets and used overloads to the RestMethod to ensure I get all the sessions (not pretty in the code, it´s also rather slow… but hey… It gets the job done!). I also wanted to test out other things as well, like RegEx and input parameters etc. and then wrapped the result in to my own custom CH9.EventItem object.

I had some challenge with the URL outlined for different events (A good documentation is found here: http://channel9apps.codeplex.com/wikipage?title=Channel%209%20RSS%20feeds&referringTitle=Channel%209%20API) , so I ended up providing them as mandatory inputs to the CmdLets (like EventName, Region and Year) even though not all Events needs them.

When I got the first “Get” CmdLet (Get-CH9EventItem) in place, it was rather handy to filter and sort result based on Speaker, Category and Title. For example, I could get all Jeffrey Snover´s sessions from Build:
$Snover = Get-CH9EventItem -EventName Build -Year 2015 -Region NorthAmerica -Speaker Snover
Image may be NSFW.
Clik here to view.
RUblogg_Ch9_Pic1

A nice thing that returned in the data, are the ability to see how long a sessions are in seconds. An easy way to transform the result to minutes and list all sessions is the example below. This is rather handy when you want to fill out your flight time with some quality videos. Image may be NSFW.
Clik here to view.
:)

$Snover | ft Title, @{n='Duration(Min)';e={$_.Duration / 60 -as [int]}} –AutoSize
Image may be NSFW.
Clik here to view.
RUblogg_Ch9_Pic2

Then I could just add even more session from other Events, like Ignite:
$Snover += Get-CH9EventItem -EventName Ignite -Year 2015 -Region NorthAmerica -Speaker Snover
Yet again, we can list the session’s title and duration in minutes (a pity not all sessions have the “Duration” set):

Image may be NSFW.
Clik here to view.
RUblogg_Ch9_Pic3

This way, I could easily fill up different variables and sort, filter, add and remove sessions all with PowerShell. A cool way to create your very own session catalog. Next, I could send all my sessions to the Save-CH9EventItem CmdLet that I created. This also have some neat features to only save the presentations or videos. By default, it saves the sessions to the “My Videos” folder if nothing else is provided to the CmdLet.
$Snover | Save-CH9EventItem
To get the CmdLet loaded on your box, download the CH9.psm1 file from here: https://gallery.technet.microsoft.com/Channel-9-Event-CmdLets-1f4ee30aThen place it in a folder called “CH9” under the path: “%UserProfile%\Documents\WindowsPowerShell\Modules”
or
“%Windir%\System32\WindowsPowerShell\v1.0\Modules” (if you want it provided for all users on the box).

For now, it supports the last years TechEd in Europe and US and also Build and Ignite. I will update this with more regions and events later on, but for now – Happy hunting for sessions!

Best regards,
Richard Ulfvin

Image may be NSFW.
Clik here to view.
Richard Ulfvin

The post A CmdLet for Channel 9 events (like Ignite) appeared first on Addlevel.


Viewing all articles
Browse latest Browse all 52

Trending Articles