Posts Tagged ‘cleanup’

Shrink and Clean Your Virtual Machines

Monday, April 15th, 2013

I’m a rabid advocate of VMWare Workstation (and Server for that matter!). I maintain a separate virtual machine – and sometimes more than one – for each client I’ve worked with over the years. This has many advantages, including the ability to pull an old VM out of the archive for a returning client, the ability to install different versions of the portal to match the client’s configuration, and the capability to run different VPN software on the same host machine at the same time (because each VM maintains its own network stack and VPN software configuration).

But having 10-20 VMs can be a bit painful to keep up-to-date and to keep the file sizes down. While I still haven’t figured out how to apply all Windows Updates via command line, each of my VMs now has a batch file that allows me to compress and optimize disk space for each of the VMs that I have. So, once a month I log into my VMs, run Windows Update, and run the below batch file to shrink things up.

You can download the cleanup.bat file, or just copy/paste from the below code. Basically, the script performs the following activities:

  1. Delete the files in c:\windows\temp
  2. Delete the temporary Windows Update files in c:\ windows\ SoftwareDistribution\ Download\
  3. Delete the IE update files
  4. Run the Disk Cleanup Utility (Note: you need to do a one-time run of the command “cleanmgr /dc /sageset: 1” to set your prefs – see the Microsoft KB Article on the topic.
  5. Empty the recycle bin
  6. Defrag the drives
  7. Run the VMWare drive shrink utility
  8. Shut down the machine

So, do you have any optimizations that you think could be added to this script?