Tag Archives: Start-Consolidation

Robert van den Nieuwendijk has a nice post on how to use PowerCLI to find VMs that need consolidation and then how to start consolidation. You can that post here: http://rvdnieuwendijk.com/2012/09/26/use-powercli-to-consolidate-snapshots-in-vsphere-5/ But, as always, I prefer to make a function of these kind of things. A function is much easier to remember than a bunch of parameters and cmdlets. So here’s the code for a function that will search through the vCentre for VMs that need disk consolidation: function Start-Consolidation { [CmdletBinding()] Param ( [string]$Location = ‘*’, [switch]$ListOnly ) $VMs = Get-VM -Location $Location | Where-Object {$_.Extensiondata.Runtime.ConsolidationNeeded} if ($ListOnly) { $VMs } else { $VMs | ForEach-Object { Write-Host “Starting disk consolidation on $_.Name” $_.ExtensionData.ConsolidateVMDisks() Write-Host “Finished disk consolidation on $_.Name” } } } Any input is much appreciated 🙂