Scott Hanselman

Download Podcasts with Powershell

November 9, '09 Comments [13] 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("http://feeds.feedburner.com/HanselminutesCompleteMP3"))
$a.rss.channel.item | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$file = $url.Segments[-1]
$file
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:

.\myscript.ps1

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. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Monday, November 09, 2009 11:40:40 PM UTC
If you're getting a script error "can't find brush: powershell" try refreshing your browser with CTRL-F5 to get the new brush.
Tuesday, November 10, 2009 3:34:44 AM UTC
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.
Tuesday, November 10, 2009 4:08:18 AM UTC
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.
Tuesday, November 10, 2009 5:56:42 AM UTC
Hi Scott,

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

Thanks
Anandraj.A.
Anandraj
Tuesday, November 10, 2009 5:58:54 AM UTC
Hi Scott,

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


Klaus
Tuesday, November 10, 2009 6:00:58 AM UTC
Here is the link to my "One script to download them all" blog post: http://www.tellingmachine.com/post/One-PowerShell-Script-to-download-them-all.aspx
Tuesday, November 10, 2009 6:02:19 AM UTC
I am very excited for reading your blog & listing your podcast. Where i learn asp.net 4.0 any good palace for learning asp.net.
Tuesday, November 10, 2009 6:07:25 PM UTC
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.

Lee
Tuesday, November 10, 2009 10:25:59 PM UTC
I'm actually looking for something fairly similar to this that will download all video related RSS feeds for my 360. This will be a good start, thanks.
Wednesday, November 11, 2009 1:09:24 PM UTC
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?

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

Regards
Mohit Thakral
Thursday, December 24, 2009 1:09:07 AM UTC
Thanks for the post Scott, this script worked where a number of applications failed. I need to learn Powershell at some point.
Monday, March 08, 2010 7:44:13 PM UTC
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.