We have a large number of VMs where free sapce on the C: drive is only 1 or 2%. While our intention is to not waste resources, we run into problems where Windows updates fail to install because there isn't enough free space. I would like to be more proactive about finding/fixing these VMs.
I'm looking for two scripts:
1. Identify all VMs that have less than 10% free space on the C: drive
2. Automatically resize the VMDK file and extend the C: partition
1) Provided you have the VMware Tools installed on all your guests, it's quite easy to find the partitions that have less than 10% free space.
Something like this
Get-VM | Get-VMGuest | %{ $vm = $_ if($_.Disks){ $_.Disks | where {($_.FreeSpace/$_.Capacity) -le 0.1 } | %{ $_ | Select @{N="VMname";E={$vm.VmName}}, @{N="Path";E={$_.Path}}, @{N="Free";E={"{0:P}" -f ($_.FreeSpace/$_.Capacity)}} } } }
2) I would need to have some extra information to do part 2 of your question
-) Is there always just 1 partition on each virtual disk ?
-) What OS are you running on those guests ? With some OS it's quite difficult to extend a partition.
-) Do you also want to include the boot partition in this ? With Windows extending the boot partition is not too straightforward.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Answers:
1. 99% of the time there is only one VMDK per partition. It would be great if the script checked and skipped any VMDK files where it finds more than 1 partition.
2. Guests are WinXP and 2003. The scripts would run from a Windows 2003 machine.
3. Boot partition - yes please I know this makes it more difficult but this is the functionality we really need.
That will be one hell of a script
Let me have a look and think about it.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not trying to push my luck - but wondering if you've had time to investigate.
Yup, this would be a good tool to have
I'm not one to say it can't be done, but I agree it will be difficult at best. There are 3rd party apps that do this well such as Vizioncore vOptimizer. It may be cheaper to just purchase this vs. spending a lot of time trying to figure it out.
Having said that if someone does I'll use it!
Anyone want to take on this challenge?