Sunday, September 18, 2011

The Build Videos–Getting Them With PowerShell

I’m just back from the //BUILD/ concerence in Anaheim – where I missed far more sessions than I could have ever hoped to attend. It was 3 1/2 days of the fire hose – I get tired just thinking about it. Luckily for us, Microsoft has taped every session and has put them up for download.

By day 2, superstar PowerShell guru James Brundage had created a great PowerShell function to download the whole set.

Get-EnclosureFile -Directory $home\Videos\Build -Feed

function Get-EnclosureFile  {
        Downloads enclosure files from a feed
        James Brundage
        Downloads enclosure files from a RSS feed using the BitsTransfer module
        Get-EnclosureFile -Directory $home\Videos\Build -Feed

# The directory where the files should go
# The Feed

begin {
Import-Module BitsTransfer –Global

process {
New-Item -ErrorAction SilentlyContinue $directory -ItemType Directory
Push-Location $directory
$Rss =(New-Object Net.Webclient).DownloadString("$Feed")
$xfer = $Rss |
    Select-Xml //item/enclosure |
        ForEach-Object {
            $url = [uri]$_.Node.Url
            $destinationFile = $_.Node.ParentNode.Title
            foreach ($char in [io.path]::GetInvalidFileNameChars()) {
                $destinationFile = $destinationFile.Replace("$char", "")
            $destinationExtension= $url.Segments[-1].Substring($url.Segments[-1].LastIndexOf("."))
            if (-not (Test-Path $destinationFile)) {
                Start-BitsTransfer -Source $url -Description $_.Node.ParentNode.Title -Destination "${destinationFile}$destinationExtension"


To call the function, just do something like this:

Get-EnclosureFile -Directory $home\Videos\Build -Feed

Of course, you better have a lot of disk space (I’ve taken up 21GB so far!). Oh – you also need a reliable connection (and you have Windows Bloody Update not decide to reboot).



John J. Kavanagh said...

Hmmm odd ... the Technorati line before the closing bracket of the function causes issues....

Thomas said...

thanks john - fixed!