VMware Cloud Community
RadarG
Enthusiast
Enthusiast

PowerCLi Snapshot help needed

I was given a mess that had over 2K VM with 7K+ snapshots with 300 of them over a year old. I ran the following on a single host of clean up some of the snaps

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date 01/Jun/2020)} | Remove-Snapshot -RunAsync -RemoveChildren -Confirm:$false

 

now I have a few dozen vms with the status "vm needs to be consolidated" consolidation fails due to a lock error. 

Where did I go wrong and how do I fix this? 

 

Reply
0 Kudos
1 Reply
jondercik2020
Contributor
Contributor

I think they may have been deleted out of order, by also doing the -RemoveChildren option.  To do this you can run something like the following code to consolidate the VMs that have errors:

$vmList = Get-VM | Sort-Object Name
                    if ( $vmList )
                    {
                        $filteredVMList = $vmList | Where-Object {$_.Extensiondata.Runtime.ConsolidationNeeded}
                        if ( $filteredVMList )
                        {
                            foreach($vm in $filteredVMList)
                            {
 
                                $vm.ExtensionData.ConsolidateVMDisks_Task() | Out-Null
                            }
                        }
                    }
Reply
0 Kudos