WPC 2016 download via PowerShell

Hi all!!!

We’ve just come back from WPC in Toronto, and as first time attendees we were blown away. Not so much by the scale of it, which is impressive in itself but not dissimilar to MEC and Ignite, but the sheer quantity of information available. You can choose to do sessions, arrange formal 1:1 meetings, catch people at various Microsoft or vendor stands or the regional lounges. Too much to do and too little time. It is full on too from around 730am breakfast until 1 or 2am back at the hotel.

As hardened techies, adjusting to WPC which is very much focused on business development and partnering, was also a challenge. We feel we rose to that challenge though and we will be back for more in Washington DC next year!

As usual Microsoft have made the content available online, but isn’t it nice to be able to use PowerShell to download what you want instead!?

So I wrote a wee script that does just that. Please note it was written in a couple of hours, so not much in the way of error checking or commenting included!  I started with the content page from Microsoft, copied the raw html containing all of the content into a new file and ensured it was valid XML. There are a few unclosed hr and img tags and XML doesn’t like   either. Anyway that didn’t take long and then I could read it into PowerShell and extract the names and links to slides and videos. I exported those into a csv file and then copied the content of that into the Get-WPC2016Content.ps1 script.

Quickly running through how the script works…

Parameters

  • DestinationFolder is the destination folder where to download the content to (defaults to %temp%\WPC2016)
  • Filter is a PowerShell ‘like’ filter to narrow down what you want to download (defaults to *)
  • DownloadSlides is a Boolean to download the slides (defaults to $true)
  • DownloadVideos is a Boolean to download the videos (defaults to $true)
  • WhatIf is a Boolean to just say what the script will do rather than actually do it (defaults to $true)

Disection

After the parameter declaration, you will see a function called Invoke-FileDownload. This function is based on the work by David Wyatt on GitHub although I had to tweak it slightly since within a registered event you can’t use script variables. So I create a MessageData variable and put the information I want into it and then pass it to the event.

$MessageData = New-Object PSObject -Property @{ProgressStatus=$ProgressStatus}

$changed = Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -MessageData $MessageData -Action {
  Write-Progress -Activity $Event.MessageData.ProgressStatus -PercentComplete $eventArgs.ProgressPercentage
 }

After the function is the CSV content within a PowerShell string and I convert that to CSV in PowerShell using ConvertFrom-CSV

$WPCContentCsv = ConvertFrom-CSV -delim ',' -Input @"
 "Title","Location","VideoCode"
 "CA02-P-Seller-101-The-A-B-Cs-of-the-P-Seller-sales-motion","http://doccloud.eventpoint.com/ws/directdownload.ashx?program=wpc2016&documentID=ba39e7e5-7349-e611-a517-00155d5066d7","CA02"

Warn the user that we’re running using WhatIf

if( $WhatIf ) {
  Write-Host 'Running with WhatIf Only' -ForegroundColor Yellow
}

Filter the content based on the filter provided

$WPCContentToDownload = $WPCContentCsv | ? { $_.title -like $Filter } | sort title

Check if the destination folder exists, if not then create it (Note there is no error checking here to see if it managed to create the folder correctly)

if(-not (Test-Path $DestinationFolder)) {
  Write-Host ("Creating folder '{0}'" -f $DestinationFolder )
  New-Item $DestinationFolder -type directory
}

Now let’s start to download the slides and videos. For each file skip it if it already exists, and use our function to download the file while displaying progress.

if( $DownloadSlides -and $WPCContentToDownload ) {
  foreach( $WPCSlide in $WPCContentToDownload ) {
    if( $WPCSlide.Location ) {
      $OutputFile = ('{0}\{1}.pptx' -f $DestinationFolder, $WPCSlide.Title )
      $URI = $WPCSlide.Location
      $ProgressStatus = ( "Downloading '{0}'" -f $OutputFile )
      Write-Host $ProgressStatus

      if( -not $WhatIf ) {
        if( (Test-Path $OutputFile) ) {
           Write-Host ("File already exists: '{0}'" -f $OutputFile) -ForegroundColor Yellow
         } else {
           Invoke-FileDownload $URI $OutputFile $ProgressStatus
         }
       }
     }
   }
 }

if( $DownloadVideos -and $WPCContentToDownload ) {
   foreach( $WPCVideo in $WPCContentToDownload ) {
     $OutputFile = ('{0}\{1}.mp4' -f $DestinationFolder, $WPCVideo.Title )
     $URI = ( 'http://cdn.tri-digital.com/WPC/2016/{0}.mp4' -f $WPCVideo.VideoCode )
     $ProgressStatus = ( "Downloading '{0}'" -f $OutputFile )
     Write-Host $ProgressStatus
     if( -not $WhatIf ) {
       if( (Test-Path ('{0}\{1}*.mp4' -f $DestinationFolder, $WPCVideo.VideoCode) ) ) {
         Write-Host ("File already exists: '{0}'" -f $OutputFile) -ForegroundColor Yellow
       } else {
         Invoke-FileDownload $URI $OutputFile $ProgressStatus
       }
     }
   }
 }

Comments

The Video content delivery network looks to be throttling the downloads on a per IP address basis from what I can see. Even running multiple downloads at the same time still maxes out at 10 Mbps. Although I’ve not tested it with vastly better broadband connected networks.

The content is huge! There are over 200 videos and slide decks, all up well over 200GB of files. So be careful! This script will happily fill up every spare bit of diskspace!

However it is a good way to get the content for offline use or viewing.

Examples

Show everything available to download

Get-WPC2016Content

Download the Vision Keynotes to %temp%\WPC2016

Get-WPC2016Content -Filter vis* -Whatif $false

Download the Vision Keynotes to c:\WPC2016

Get-WPC2016Content -Filter vis* -Whatif $false -DestinationFolder 'C:\WPC2016'

Download all of the slides to %temp%\WPC2016

Get-WPC2016Content -Whatif $false -DownloadVideos $false

Download all of the videos to %temp%\WPC2016

Get-WPC2016Content -Whatif $false -DownloadSlides $false

Download everything to %temp%\WPC2016

Get-WPC2016Content -Whatif $false

The Script

*** As always the script is provided on an as is basis, please test it before you use it in a production environment. ***

Get-WPC2016Content.ps1

Twan van Beers

Twan is a senior consultant with over 20 years of experience. He has a wide range of skills including Messaging, Active Directory, SQL, Networking and Firewalls. Twan loves to write scripts and get deep and dirty into debugging code, in order to understand and resolve the most complex of problems.

Leave a Reply

Your email address will not be published. Required fields are marked *

Search