Compress Every powered off VM’s VHDs

Well its not exchange related but I run all my labs in hyper-v and I recently wanted to compress all the dynamic disks in my hyper-v lab and me being lazy did not want to go to the options on EVERY VM to compress the drives, so I started my google search to find a Powershell script to do them all for me…… well I couldn’t find it so I made one of my own and figured I would share 🙂

FYI- you need SCVMM to run this

Get-VMMServer –ComputerName localhost -TCPPort  8100 (8100 is default)

get-vm | where {$_.status -eq “POwerOFf”} | Get-VirtualDiskDrive |where {$_.status -eq “POwerOFf”}| ForEach-Object {Compress-VirtualDiskDrive -RunAsynchronously -VirtualDiskDrive $_}

Note: this will compress everything that’s “shutdown” so make sure you have the Disk I/O to do this.


3 thoughts on “Compress Every powered off VM’s VHDs

  1. Pingback: Compress Every powered off VM’s VHDs « JC’s Blog-O-Gibberish

  2. Hi,

    Just Found this blogpost from my Technorati upcomming news event Story section. really interesting post , that’s why subscribed your RSS feeder, Hope you will add more usefull posts soon.

    Keep it Up.

  3. Are you sure the where {$_.status -eq “POwerOFf”}| is needed for Get-VirtualDiskDrive? Seems like if the host VM is off the VHD would be . But excellent one liner script regardless…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s