Last November I had the pleasure of attending the SharePoint Connect 2014 Amsterdam conference at De Meervaart Theatre. Organizer NC Communication was nice enough to share the slides on SlideShare.net at http://www.slideshare.net/nccomms/ with the prefix title “SPCA2014”.
There are about 25 slide decks and the amount of clicking to download them is daunting! Time for a PowerShell script!
I devised the following PowerShell script for downloading these slides using the SlideShare API. If you want to run it for yourself, you’ll have to apply for an API key at http://www.slideshare.net/developers/applyforapi and insert the credentials in the script.
And I had so much fun that I started a PowerShell module for talking with the SlideShare API. Stay tuned…
$slideshareUser = 'nccomms' $slidedeckTitleFilter = 'SPCA2014*' # Folder to download the slides to $downloadfolder = 'C:\TEMP\SharePointConnect2014' # Personal SlideShare API keys; # apply for a key here: http://www.slideshare.net/developers/applyforapi $slideShareAPIKey = 'YOUR_API_KEY' #PRIVATE $slideShareSharedSecret = 'YOUR_SHARED_SECRET' # Unix timestamp $ts = [int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s)) # Create an SHA1 hash from the concatenation of the shared secret and the timestamp $hash = ([System.Security.Cryptography.HashAlgorithm]::Create('SHA1').ComputeHash((New-Object System.Text.UTF8Encoding).GetBytes("$slideShareSharedSecret$ts")) | foreach { $_.ToString("x2") }) -join '' $slideshareAPIGetSlideShowsForUserUri = "https://www.slideshare.net/api/2/get_slideshows_by_user?username_for=$slideshareUser&limit=9999&api_key=$slideShareAPIKey&hash=$hash&ts=$ts" # Now query the SlideShare API for user NCCOMMS slides Write-Host "Query SlideShare API: $slideshareAPIGetSlideShowsForUserUri" $spa2014SlideData = Invoke-RestMethod -uri $slideshareAPIGetSlideShowsForUserUri if ($spa2014SlideData.SlideShareServiceError) { Write-Host "ERROR while calling SlideShare API:" -ForegroundColor RED $spa2014SlideData.SlideShareServiceError.Message | foreach { Write-Host $_.'#text' -ForegroundColor RED } } else { Write-Host "Downloading the slide decks..." # Parsing the query results foreach ($slidedeckEntry in ($spa2014SlideData.User.Slideshow | where { $_.Title -like $slidedeckTitleFilter })) { # Now process each slideshow entry # Get the SlideShare PDF download url (which points to Amazon S3) $sourceFile = $slidedeckEntry.DownloadUrl # Extract the filename $filename = (New-Object Uri($sourceFile)).Segments | select -last 1 # get filename part of the url $destFilePath = (Join-Path $downloadfolder $filename) Write-Host "From `"$SourceFile`"`nTo `"$destFilePath`"" # And download the deck file to the specified download folder Invoke-WebRequest -Uri $sourceFile -OutFile $destFilePath } Write-Host "Completed downloading the slide decks." }