Get-VM – Retreving a list of VMs in your envirnoment

First thing to remember is to connect to the VCAS.

Connect-VIServer <hostname_of_your_server>

Meet the GET-VM command!


Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] 
    [-Datastore <StorageResource[]>] [-Location <VIContainer[]>]
    [-Tag <Tag[]>] [-NoRecursion] [<CommonParameters>]

If you want to retrieve VMs connected to specific Virtual Switch:

Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] [-VirtualSwitch 
    <VirtualSwitchBase[]>] [-Tag <Tag[]>] [<CommonParameters>]

If you want to retrieve VMs by ID:

Get-VM [-Server <VIServer[]>] -Id <String[]> [<CommonParameters>]

If you want to retrieve VMs by related object:

Get-VM -RelatedObject <VmRelatedObjectBase[]> [<CommonParameters>]

Let’s start to list your VMs. This is general report:


It will produce a list of all VMs. You will see the name, power state, the number of CPU’s, and the amount of memory in GB for each virtual machine:

You can manipulate properties with the Select-Object cmdlet.

Get-VM | Select-Object -Property Name,Notes,VMHost,Guest

The output will look like this:

Name              Notes      VMHost        Guest
----              -----      ------        -----
DC1               DC Server DC1:
VM1                 VM1:
DNS1              DNS Server DNS1:

You can also use wildcard characters to select specific virtual machines:

Get-VM -Name A*
Get-VM -Name ??e
Get-VM -Name [bc]*

Using the Where-Object cmdlet, you can set the filter on any property, this command will generate a list of all of your virtual machines that have more than one virtual CPU:

Get-VM | Where-Object {$_.NumCPU -gt 1}

To list VMs in PowerOn state:

(Get-VM).where{$_.PowerState -eq 'PoweredOn'}

To list VMs in PowerOn state and with Windows OS:

(Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'}

I hope those few examples will help you with Get-VM.

If you need explanation or you do have any questions related to this script, please do not hesitate to leave the comment.

Visit my FB page:

Subscribe to my YouTube channel:

Please leave the comment