PowerShell Genie

Inventory Hyper-V VMs

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

List Hyper-V guests with Get-VM and report state, CPU usage, assigned memory in bytes, and status for each virtual machine.

The script

1PS> Get-VM | Select-Object Name,State,CPUUsage,MemoryAssigned,Status

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 State CPUUsage MemoryAssigned Status
    2 ---- ----- -------- -------------- ------
    3 VM-WEB01 Running 4 4294967296 Operating normally
    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,State,CPUUsage,MemoryAssigned,Status
    1. Stage 1Get-VMPositional values or no named parameters
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-VM returns the guests registered on the local host, and the projection keeps the name with State, the CPUUsage percentage, MemoryAssigned in bytes, and the Status string that surfaces conditions such as a degraded configuration.

      Adapting it

      Pass -ComputerName with a list of host names to gather several hosts into one table, and divide MemoryAssigned by 1GB so the column can be read without counting digits.

      Requirements

      Hyper-V PowerShell module and membership in Hyper-V Administrators.

      If the result is unexpected

      The Hyper-V VM list is empty or belongs to the wrong host.

      The session may be querying the local machine or lack the module, role or remote access required.

      1. Confirm the Hyper-V host parameter and query a known VM under the intended identity.

      Validate the result

      The output names the queried host and includes the known VM.

      Keep the check reliable

      Keep host context explicit in multi-host inventory.

      Primary documentation

      Windows services and processes documentation

      Continue
      Genie guideInventory Hyper-V VMs

      List Hyper-V guests with Get-VM and report state, CPU usage, assigned memory in bytes, and status for each virtual machine.