PowerShell Genie

Inventory VMware VMs

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-VM against a connected vCenter returns the guests, and the projection keeps the name with PowerState, NumCpu, MemoryGB, and the VMHost the guest is running on.

The script

1PS> Get-VM | Select-Object Name,PowerState,NumCpu,MemoryGB,VMHost

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name PowerState NumCpu MemoryGB VMHost
    2 ---- ---------- ------ -------- ------
    3 VM-WEB01 PoweredOn 4 8 esx01.contoso.example
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-VM | Select-Object Name,PowerState,NumCpu,MemoryGB,VMHost
    1. Stage 1Get-VMPositional values or no named parameters
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-VM against a connected vCenter returns the guests, and the projection keeps the name with PowerState, NumCpu, MemoryGB, and the VMHost the guest is running on. MemoryGB arrives already converted, so no arithmetic is needed in the projection.

      Adapting it

      Add -Location with a cluster or folder name to scope the query, since a full inventory against a large vCenter takes noticeably longer than most people budget for.

      Requirements

      VMware PowerCLI with an active Connect-VIServer session.

      If the result is unexpected

      VMware inventory contains duplicates or misses a vCenter.

      The session may have multiple default server connections or connect to the wrong inventory scope.

      1. List active server connections and query a known VM on an explicit server.

      Validate the result

      Each VM is associated with its vCenter and inventory identity.

      Keep the check reliable

      Use explicit server context and retain stable IDs when combining inventories.

      Primary documentation

      Windows services and processes documentation

      Continue
      Genie guideInventory VMware VMs

      Get-VM against a connected vCenter returns the guests, and the projection keeps the name with PowerState, NumCpu, MemoryGB, and the VMHost the guest is running on.