I came across an interesting script on Reddit /r/PowerShell recently. It was an answer to a request for a remote disk clean script that could run across a network. Looking at the code I decided the script could do with a little tidy up and rewrite.

If you look at the original code you will find it is environment specific. Some of it has poor design and does not inspire confidence:

$temp = get-ChildItem "env:TEMP"
$temp2 = $temp.Value

I completely rewrote the script using the original as a basis for the tasks to perform. It now includes:

Help.
Although it is easy to understand I have included comment based help.
Individual Tasks.
The tasks are able to run independent of each other.
Custom Removal.
You can now remove a custom list of files or folders.

This isn’t a script that’s needed every day. But it is an easy way to perform a disk clean.

Find the full script on Github.

Paul Broadwith avatar
Paul Broadwith

Paul is a Senior Technology Engineer with 25 years experience in finance, government, manufacturing and services industries. He is a father, Cloud and Datacenter MVP, coder and loves to automate everything.

comments powered by Disqus