Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

How to PowerCLI VMware Snapshots Virtual Machines disks consolidation is needed

In earlier part Solved: VMware Snapshots Virtual Machines disks consolidation is needed I performed steps on vCenter Portal GUI. Here I will use VMware PowerCLI to perform the same steps to automate it. 

First step is to connect to vCenter server using command Connect-VIServer. Use below command to get the list of VMs where snapshot disks consolidation is required with status true or false.

Get-VM | Select-Object Name, @{N="Consolidation_Needed"; E={$_.ExtensionData.Runtime.consolidationNeeded}}

VMware vsphere vcenter esxi powercli connect-viserver credential get-vm Select-object administrator@vsphere.local extensiondata runtime consolidationneeded.png

Using below command I can get the only VMs list where snapshot consolidation is required. To initiate consolidation on VMs, use method ConsolidateVMDisks_Task(). To check the status of consolidation use command Get-Task.

Get-VM | Where-Object {$_.ExtensionData.Runtime.ConsolidationNeeded}
Get-VM | Where-Object {$_.ExtensionData.Runtime.ConsolidationNeeded} | Foreach-Object {$_.ExtensionData.ConsolidateVMDisks_Task()}

Get-Task

Vmware vsphere vcenter esxi consolidation powercli get-vm where-object extensiondata runtime snapshot consolidation needed consolidatevmdisks_task() automation.png

Useful Articles
PowerCLI oneliner get the list of users and groups from vCenter SSO
PowerCLI Connect-VIServer Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction
PowerCLI Gather complete Virtual Distributed Switch (VDS) information from VMware vCenter
VMware PowerCLI Find vCenter server name of any inventory object
Create List or Remove VMware VM Snapshots with PowerCLi
VMware PowerCLI Clone and Deploy VM from template in vCenter
VMware PowerCLI Clone VM from template with customization specs in vCenter
Upgrade vCenter Server Appliance (VCSA) with VMware PowerCLI
Staging vCenter Server Appliance (VCSA) updates using Rest API

Go Back

Comment

Blog Search

Page Views

12278701

Follow me on Blogarama