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??
-
This script will only run between 7 AM and 11 PM.
- Clears all code off the screen
- Stops the Windows Update Service
- Deletes the contents of windows software distribution
- Deletes the contents of windows temp folder
- Deletes files in users temp folder
- Deletes temporary internet files
- Cleans IIS logs
- Empties the Recycling Bin
- Starts Windows update service
- Opens and runs Disk cleanup — must click OK in GUI 😦
- Outputs disk space before and after.
After copying all of the above code into an elevated PowerShell prompt just simply type the following:
output:
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.