Wednesday, March 20, 2013

Clean up old files using PowerShell

I've been working on this blog for just over 6 months now, and my most popular article, by far, is about using PowerShell to extract worksheets from an Excel file. I basically took an old script idea I'd found really useful in a past project, and created a version of it in PowerShell. It was fun to write, and since there's been a lot of interest, I decided to do another one; this time, to help with file cleanup.

Doing a quick Google search (which may be what brought you here) will show you a number of variations on PowerShell scripts for deleting files. I'm sure many of them are perfectly adequate for the task, and in some cases, have features that mine doesn't. My solution excels at code readability and control, the latter of which I feel is fairly important when deleting files in bulk.

Not much else to say about it I guess; the purpose and uses of this script are pretty straightforward.

Here's the code:

NOTE: If you run into problems getting the script to run on your machine, there are a few troubleshooting tips in my original article.