Scott Hanselman

Download Podcasts with Powershell

November 10, 2009 Comment on this post [10] Posted in Podcast | PowerShell
Sponsored By

A number of people have mentioned to me that they didn't realize that Powershell is included by default in Windows 7. If you haven't yet jumped on the Powershell bandwagon, this is a good time. Powershell 2 includes a bunch of cool features like remoting (kind of like SSH) as well as a visual IDE for writing, editing and interactively debugging Powershell scripts.

Windows PowerShell ISE (2)

Powershell great for system administration, but I mostly use it for quick and dirty "portable" apps that I don't feel like writing C#/VB for. Plus, I'm using .NET anyway, so it's all the same.

I wanted to download all my podcasts with Powershell, so I wrote this quick script in about 5 minutes. Other improvements I (or preferably you) could make to it could be: check the file size against the enclosure and re-download partials, rename the files to included a version of the title, include a progress bar.

Here's what I came up with. Perhaps you'll find it useful if you're not an iTunes/Zune person:

cd "C:\users\scottha\desktop\Hanselminutes Complete Download"
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$a = ([xml](new-object net.webclient).downloadstring(""))
$ | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$file = $url.Segments[-1]
if (!(test-path $file))
(New-Object System.Net.WebClient).DownloadFile($url, $file)

Of course you'll want to change the first line and the RSS Feed URL as you like.

Hanselminutes Complete Download

If you've never used Powershell before, note that it's locked down from running scripts be default. You'll need to run it as Administrator once and run

Set-ExecutionPolicy unrestricted

This opens it up to run scripts, but it's not only VBS, the scripts won't run if you double-click them. You need to run powershell then type the name of your script to run it:


You can always set the execution policy back if it bothers you.

Hope this primitive mass podcast enclosure downloader is useful.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
November 10, 2009 3:40
If you're getting a script error "can't find brush: powershell" try refreshing your browser with CTRL-F5 to get the new brush.
November 10, 2009 7:34
Amazing what you can do with a little PowerShell. :)

BTW - RemoteSigned is a safer option than Unrestricted.

Set-ExecutionPolicy RemoteSigned

That way local scripts run without problem, but downloaded scripts need a signature or to be explicitly unblocked by the user.
November 10, 2009 8:08
I wrote a script 18 months ago to do exactly what you've just described here: Download Hanselminutes with Powershell. At that time you'd published 109 shows and now you're up to 189. We spoke briefly about it at MIX09 after the Stackoverflow recording but there were a lot of people around so I understand if you don't remember me.

Thanks for blogging about this. I'm a big fan of Powershell for automating anything that I have to do more than once.
November 10, 2009 9:56
Hi Scott,

Can you please guide me where to start to learn powershell from basics?

November 10, 2009 9:58
Hi Scott,

I did something similar with PowerShell. I downloaded all PDC2008 content with one PowerShell script.

November 10, 2009 10:00
Here is the link to my "One script to download them all" blog post:
November 10, 2009 22:07
Re: the execution policy... +1 on what James says. In addition, the -Scope parameter lets you set the Execution Policy for just the CurrentUser, meaning you don't need to be admin.

November 11, 2009 17:09
Powershell syntax is simply: horrible.

It must have been developed by an incomplete convert from Linux command line religion.
Why not some cleaner syntax, c# style?

Abomination: [Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath...

or New-Object... why not New-NET-Framework-Clr-Object?

November 11, 2009 19:24
From where Can i download, Windows Powershell v 2.0. I have windows 7x 64 pro. I can't c powershell ISE in there.

Mohit Thakral
March 08, 2010 23:44
Thanks for the post! This just came in very handy. I forget sometimes how awesome Powershell is.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.