PowerCLI: Consolidating virtual machine disks

In order to retrieve a list of virtual machines which are reporting t the issue ‘Virtual machine disks consolidation is needed’ we can invoke the Get-VM cmdlet to determine if a virtual machine consolidation is required.

$VMs = Get-VM | Where-Object {$_.ExtensionData.RunTime.ConsolidationNeeded}

To consolidate snapshots for a collection of virtual machines we can now perform the following, where the virtual machine consolidation will complete before invoking the script block on the next object.

ForEach ($VM in $VMs)

    { 
    (Get-VM $VM).ExtensionData.ConsolidateVMDisks()
    } 
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s