A collection of one liners that get/set useful information from vCenter via PowerCLI.   For use when the the UI is just way to slow.

Getting list of all VMs and Mounted ISO

Get-VM | Get-CDDrive | select @{N=”VM”;E=”Parent”},IsoPath | where {$_.IsoPath -ne $null}

Get-VM | Get-CDDrive | select @{N="VM";E="Parent"},IsoPath | where {$_.IsoPath -ne $null}

Getting backups and size

Get-VM | Format-Table Name, @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}, @{Label="TotalSnapShotSizeMB";Expression={(Get-Snapshot -VM $_ | Measure-Object -Sum SizeMB).Sum}}

Getting the UUID of all VMs

Get-VM | select Name,@{n=”UUID”;e={$_.ExtensionData.Summary.Config.Uuid}}

 Get-VM | select Name,@{n="UUID";e={$_.ExtensionData.Summary.Config.Uuid}} 

or

 Get-VM| %{(Get-View $_.Id).config.uuid}

uuid and moref

 Get-VM | select Name,@{n="UUID";e={$_.ExtensionData.Summary.Config.Uuid}},@{n="MOREF";e={$_.ExtensionData.MoRef}} 

Getting the Connection State for NICs

Need to see which NICs are connected (and presumably in use) but are not configured to start connected.

Get-VM | Get-NetworkAdapter | select @{N=’VMName’;E={$_.Parent}}, @{N=’NICType’;E={$_.Type}}, @{N=’StartConnected’;E={$_.ExtensionData.Connectable.StartConnected}}, @{N=’Connected’;E={$_.ExtensionData.Connectable.Connected}}

 Get-VM | Get-NetworkAdapter | select @{N='VMName';E={$_.Parent}}, @{N='NICType';E={$_.Type}}, @{N='StartConnected';E={$_.ExtensionData.Connectable.StartConnected}}, @{N='Connected';E={$_.ExtensionData.Connectable.Connected}}

Shortened from the script http://pio.nz/2017/04/03/get-connection-state-of-vm-nics/

One liner VMware PowerCLI snippets

Leave a Reply

Your email address will not be published. Required fields are marked *