VMware Cloud Community
brittonv
Contributor
Contributor

Get the same Information from "Virtual Machines" tab via PowerShell

Greetings,

When I click the Virtual Machines tab from my Home/Inventory/VM's and Templates I get a list of all my VM's, complete with some custom fields.

Is there a way to get all this same information from Powershell?

It has been suggested to me that I will need to run an SQL query to gain this information. If that is indeed necessary, how do I perform an SQL Query against the VMWare Database?

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

There is no need to get this data from the SQL db.

You can get that information with PowerCLI (except for the graphical elements in there).

In fact you could get the graphical elements but that would require using WPF or something similar.

The information on that page via a script

$report = @()

Get-VM | %{
	$row = "" | Select Name, State, Status,Host,"Provisioned Space","Used Space","Host CPU - MHz",
					"Host Mem - MB","Guest Mem - %",Notes,"Alarm Actions"
	$_ | Get-Annotation | %{
		$row | Add-Member -Name $_.Name -Value $_.Value -MemberType NoteProperty
	}
	$vm = $_ | Get-View

	$row.Name = $_.Name
	$row.State = $_.PowerState
	$row.Status = $vm.Summary.OverallStatus
	$row.Host = $_.Host.Name
	$row."Provisioned Space" = ("{0:N2}" -f (($vm.Summary.Storage.Committed + $vm.Summary.Storage.Uncommitted) / 1GB)) + " GB"
	$row."Used Space" = ("{0:N2}" -f ($vm.Summary.Storage.Committed / 1GB)) + " GB"
	$row."Host CPU - MHz" = $vm.Summary.QuickStats.OverallCpuUsage
	$row."Host Mem - MB" = $vm.Summary.QuickStats.HostMemoryUsage
	$row."Guest Mem - %" = "{0:P0}" -f ($vm.Summary.QuickStats.GuestMemoryUsage / $vm.Summary.Config.MemorySizeMB)
	$row.Notes  = $_.Description
	$row."Alarm Actions" = &{if($vm.AlarmActionsEnabled){"Enabled"} else{"Disabled"}}
	$report += $row
}
$report | ft -AutoSize -Force

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos