Cleanup a C: drive w/ Windows PowerShell

title

Being an overnight Administrator I get a lot of low disk space alerts when drives hit their thresholds. Tonight I’m going to put an end to all this work. I wrote the following script with little bits of help from people all over the web. I’d like to thank everyone for contributing, if it weren’t for all of you I would not know any PowerShell. (Scary Thought!)

What Does this Script do??

  1. This script will only run between 7 AM and 11 PM.
  2. Clears all code off the screen
  3.  Stops the Windows Update Service
  4. Deletes the contents of windows software distribution
  5. Deletes the contents of windows temp folder
  6. Deletes files in users temp folder
  7. Deletes temporary internet files
  8. Cleans IIS logs
  9. Empties the Recycling Bin
  10. Starts Windows update service
  11. Opens and runs Disk cleanup — must click OK in GUI 😦
  12. Outputs disk space before and after.

top

bottom

After copying all of the above code into an elevated PowerShell prompt just simply type the following:

clean

output:

bott

Note this would have cleaned up more files and given a long verbose string of files removed except I’ve been testing these cmdlets all night which has already whipped my system clean of all of these files.

Download my script here!