Download TechEd Sessions Automatically by Using PowerShell

Download TechEd Sessions Automatically by Using PowerShell

  • Comments 10
  • Likes

Summary: Microsoft Windows PowerShell MVP, Marco Shaw, shows how to use Windows PowerShell to automatically download TechEd sessions.

Microsoft Scripting Guy, Ed Wilson, here. Today we have a guest blogger: Microsoft Windows PowerShell MVP, Marco Shaw.

Downloading Microsoft TechEd sessions automatically

Microsoft’s TechEd conference is the best conference for getting up to speed on Microsoft’s entire product line. This is the latest information about Microsoft products, delivered by subject matter experts. Sometimes the sessions are delivered by actual members of the product teams, and other sessions are delivered by Microsoft Most Valuable Professionals (MVPs). There are sessions designed for all levels, including ITPros and developers. There’s usually two conferences per year, one in the United States and one in Europe.

In 2010, Microsoft started posting online videos from the sessions for the public to view for free. You can’t beat free!

TechEd 2011 was in Atlanta this year, and it just wrapped up a few weeks ago. What is super cool this year is that Microsoft posted the videos online within 24-48 hours after a session completed. There are over 450 downloadable sessions that cover all kinds of technologies. So you better start downloading…

Better yet, let’s let Windows PowerShell do all the hard work for us.

Fortunately, Microsoft has made the session data available by using the Open Data Protocol (OData) to allow for any source to be able to query the session data using the HTTP protocol.

Windows PowerShell 2.0 doesn’t have any out-of-the-box ability to understand the OData protocol, but fortunately, Doug Finke comes to the rescue with a Windows PowerShell module for OData! I’m not going to go through how to download and install the module here, so if you’ve never done anything with non-Microsoft modules, you may have to do a bit of searching.

I wanted to implement a few things in my code:

  • The ability to download all sessions.
  • The ability to download just a track (or multiple tracks)
  • The ability to list the tracks.
  • The ability to get the title for a session.
  • The ability to get the abstract for a session.
  • The ability to have some kind of idea what’s going on (these sessions can take awhile to download).
  • Use the BITS module to transfer the files.
  • Download the regular session only (not the high-definition session).

Here’s the code that implements all of these things (with comments):

param([switch]$list,[string[]]$track,[switch]$all,[string]$title,[string]$abstract)

 

# Added this hashtable to provide a more friendlier name.

$tracks=@{"COS"="Cloud Computing and Online Services";

  "DBI"="Database and Business Intelligence";

  "DEV"="Developer Tools, Languages and Frameworks";

  "DPR"="Development Practices and Architecture";

  "EXL"="Exchange and Lync";

  "MID"="Middleware and Integration";

  "OSP"="Office and SharePoint";

  "SIM"="Security, Identity and Management";

  "VIR"="Virtualization";

  "WCL"="Windows Client";

  "WPH"="Windows Phone";

  "WSV"="Windows Server"}

 

# Just a listing of the tracks above. 

if($list){$tracks;Write-Host "";break}

 

# Save the data to a global variable.  Can save from downloading the data every time the script is invoked.

if(!(Get-Variable -Name teched_odata -Scope Global -ErrorAction "SilentlyContinue")){

  try {Import-Module -Name OData -ErrorAction "Stop"} catch {Write-Host "OData module not found.";break}

  try {$global:teched_odata=New-ODataService -Service "http://odata.msteched.com/tena2011/sessions.svc"} catch {Write-Host "OData download failed.";break}

}

 

# Save the sessions to a variable, so they might load faster later.

# You could look at the object using Get-Member to see that sessions() is the method to call.

$sessions=$global:teched_odata.sessions()

 

# Just get the title for a particular session.

if($title){

  $sessions|Where-Object{$_.code -eq $title}|Select-Object -Property Title

}

 

# Just get the abstract (full description) for the session.

if($abstract){

  $sessions|Where-Object{$_.code -eq $abstract}|Select-Object -Property Abstract

}

 

if($track){

  Import-Module -Name BitsTransfer

  # This is a special URL that provides part of the location where the session is stored.

  $ch9="http://media.ch9.ms/teched/na/2011/wmv/"

  # Count the total number of sessions to download.

  foreach($code in $track){

    $script:total_sessions=1

    # There's several sessions that don't appear to be downloadable.  Filtering out on the Code property only being 6 characters.

    # Also matching the first 3, because that's the tracks from the session that we are looking for.

    foreach($session in $($sessions|Where-Object{($_.code.tostring().length -eq 6) -and ($_.code.substring(0,3) -eq $code)})){

      $script:total_sessions++

    }

  }

  # Download each session.

  foreach($code in $track){

    $script:current_session=1

    # There's several sessions that don't appear to be downloadable.  Filtering out on the Code property only being 6 characters.

    # Also matching the first 3, because that's the tracks from the session that we are looking for.

    foreach($session in $($sessions|Where-Object{($_.code.tostring().length -eq 6) -and ($_.code.substring(0,3) -eq $code)}|Select-Object -ExpandProperty code)){

      # Make sure the session hasn't already been downloaded.

      if(!(Test-Path -Path $($pwd.path+"\"+$session+".wmv"))){

        # Outter progress bar on overall download.

        Write-Progress -Activity "Overall progress" -Status $([string]$script:current_session+" of "+[string]$script:total_sessions) -PercentComplete $((${script:current_session}/$script:total_sessions)*100)

        # Progress bar of each session download.

        Start-BitsTransfer -Source $("http://media.ch9.ms/teched/na/2011/wmv/"+$session+".wmv") -Destination $($pwd.path+"\"+$session+".wmv")

      }

      else{

        Write-Host "${session}.wmv already exists in the local directory."

      }

      $script:current_session++

    }

  } 

}

 

# Download all the sessions.

if($all){

  Import-Module -Name BitsTransfer

  # This is a special URL that provides part of the location where the session is stored.

  $ch9="http://media.ch9.ms/teched/na/2011/wmv/"

  # Count the total number of sessions to download.

  foreach($code in $track){

    $script:total_sessions=1

    # There's several sessions that don't appear to be downloadable.  Filtering out on the Code property only being 6 characters.

    foreach($session in $($sessions|Where-Object{($_.code.tostring().length -eq 6)})){

      $script:total_sessions++

    }

  }

  $script:current_session=1

  # There's several sessions that don't appear to be downloadable.  Filtering out on the Code property only being 6 characters.

  foreach($session in $($sessions|Where-Object{$_.code.tostring().length -eq 6}|Select-Object -ExpandProperty code)){

    # Make sure the session hasn't already been downloaded.

    if(!(Test-Path -Path $($pwd.path+"\"+$session+".wmv"))){

      # Outter progress bar on overall download.

      Write-Progress -Activity "Overall progress" -Status $([string]$script:current_session+" of "+[string]$script:total_sessions) -PercentComplete $((${script:current_session}/$script:total_sessions)*100)

      # Progress bar of each session download.

      Start-BitsTransfer -Source $("http://media.ch9.ms/teched/na/2011/wmv/"+$session+".wmv") -Destination $($pwd.path+"\"+$session+".wmv")

    }

    else{

      Write-Host "${session}.wmv already exists in the local directory."

    }

    $script:current_session++

  } 

}

Because this script is rather long, I have uploaded it to the Scripting Guys Script Repository. This will enable you to get the code, and to not have to worry about copy and paste errors, or picking up strange HTML characters in your script.

Let’s walk through some examples for using this script.

Get a list of all the available tracks:

Image of code

Download all of the sessions in the track WSV:

Image of code

Download all of the sessions from all of the tracks:

Image of code

Get the session information for COS202:

Image of code

As you can see, the abstract can be quite long, so finding the proper way to format it for your particular use may pose a small challenge.

So there you go…a Windows PowerShell TechEd session downloader. I used it to download almost 300 sessions (nearly 53 GB of data). So instead of wasting my time clicking through 300 sessions, and then checking every time to see if one was done before starting another, I was able to open a Windows PowerShell session, start my script and let it run. It must have run for over 25 hours. In the middle of it, I needed to reboot my computer to update some device drivers, so the check that I added to see if a session was already downloaded definitely helped out.

Can’t wait until TechEd 2012! I should have enough time to review my 300+ hours of sessions by then.

Thank-you for this posting, Marco! Join me tomorrow when we will be joined by guest blogger, Microsoft Windows PowerShell MVP, Sean Kearney.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • ..Or, just watch those sessions online using this: www.ravichaganti.com/blog

  • Great work! Unforunately i am able to get the -list, but nothing more. I always get "OData module not found". :/

    I have downloaded the OData Module and used Import-Module.

  • cancel that :D figured out my mistake.

  • Christian ... do you mind sharing what you did?  I know it is my lack of powershell experience, but still need to know.  I also have downloaded the OData module and used Import-Module.  I am getting 'OData module not found.'

  • @Joanne

    Here's how I worked that OData thing...

    Downloaded the file

    Extracted the ODataPowerShellExplorer.zip file somewhere

    Then inside my modules folder (c:\users\<YOU>\Documents\WindowsPowerShell\Modules) I created another folder and called it OData

    Then I copied the OData.psm1 file from where I extracted that ODataPowerShellExplorer.zip file to that Modules\OData folder I created

    I could then import-module -Name OData and use Marco's script above

    There's more to do, in order to use the OData module to it's full potential

  • @Joanne: I can write a detailed post over the weekend if you are still stuck.  Don't forget to right click on the zip first and "unblock" it.  Makes things easier...

  • I've updated the script in the repository to v1.1.  I've added -mp4 and -hd switches to download the MP4 and High Def versions respectively.

  • I got it guys, thanks.

  • "Can’t wait until TechEd 2012!" , well it is here! where is the script to download that? ;)

  • @Arjang: Funny you ask...  I'm writing one up for TechhEd New Zealand right now.  I was lazy and downloaded the TechEd North America one by hand...  PowerShell gods: I have sinned!