« Herding Cats: Organize your Desktop Icon... | Main | Our little team is growing - Welcome to ... »

Download Podcasts with Powershell

Posted 2009-11-09 03:38 PM in Podcast | PowerShell.

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.



Monday, November 09, 2009 3:40:40 PM (Pacific Standard Time, UTC-08:00)
If you're getting a script error "can't find brush: powershell" try refreshing your browser with CTRL-F5 to get the new brush.
Monday, November 09, 2009 7:34:44 PM (Pacific Standard Time, UTC-08:00)
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.
Monday, November 09, 2009 8:08:18 PM (Pacific Standard Time, UTC-08:00)
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.
Monday, November 09, 2009 9:56:42 PM (Pacific Standard Time, UTC-08:00)
Hi Scott,

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

Thanks
Anandraj.A.
Anandraj
Monday, November 09, 2009 9:58:54 PM (Pacific Standard Time, UTC-08:00)
Hi Scott,

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


Klaus
Monday, November 09, 2009 10:00:58 PM (Pacific Standard Time, UTC-08:00)
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
Monday, November 09, 2009 10:02:19 PM (Pacific Standard Time, UTC-08:00)
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 10:07:25 AM (Pacific Standard Time, UTC-08:00)
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 2:25:59 PM (Pacific Standard Time, UTC-08:00)
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 5:09:24 AM (Pacific Standard Time, UTC-08:00)
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 7:24:01 AM (Pacific Standard Time, UTC-08:00)
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
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, pre, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Live Comment Preview

Contact

Sponsors

Hosting By

Hot Topics

Tags

Calendar

<November 2009>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Archives

November, 2009 (5)
October, 2009 (19)
September, 2009 (11)
August, 2009 (12)
July, 2009 (21)
June, 2009 (26)
May, 2009 (16)
April, 2009 (13)
March, 2009 (17)
February, 2009 (17)
January, 2009 (18)
December, 2008 (32)
November, 2008 (17)
October, 2008 (22)
September, 2008 (16)
August, 2008 (14)
July, 2008 (25)
June, 2008 (19)
May, 2008 (17)
April, 2008 (17)
March, 2008 (26)
February, 2008 (21)
January, 2008 (28)
December, 2007 (19)
November, 2007 (17)
October, 2007 (31)
September, 2007 (39)
August, 2007 (37)
July, 2007 (43)
June, 2007 (37)
May, 2007 (32)
April, 2007 (38)
March, 2007 (29)
February, 2007 (46)
January, 2007 (31)
December, 2006 (27)
November, 2006 (31)
October, 2006 (32)
September, 2006 (39)
August, 2006 (34)
July, 2006 (40)
June, 2006 (18)
May, 2006 (31)
April, 2006 (34)
March, 2006 (30)
February, 2006 (38)
January, 2006 (44)
December, 2005 (19)
November, 2005 (34)
October, 2005 (24)
September, 2005 (37)
August, 2005 (20)
July, 2005 (24)
June, 2005 (33)
May, 2005 (16)
April, 2005 (22)
March, 2005 (34)
February, 2005 (15)
January, 2005 (37)
December, 2004 (28)
November, 2004 (30)
October, 2004 (34)
September, 2004 (22)
August, 2004 (34)
July, 2004 (18)
June, 2004 (64)
May, 2004 (49)
April, 2004 (21)
March, 2004 (29)
February, 2004 (29)
January, 2004 (36)
December, 2003 (25)
November, 2003 (24)
October, 2003 (59)
September, 2003 (42)
August, 2003 (24)
July, 2003 (44)
June, 2003 (29)
May, 2003 (21)
April, 2003 (30)
March, 2003 (27)
February, 2003 (47)
January, 2003 (50)
December, 2002 (31)
November, 2002 (38)
October, 2002 (44)
September, 2002 (15)
May, 2002 (2)
April, 2002 (4)

Google Ads