Get-VM

This cmdlet retrieves the virtual machines on a vCenter Server system. Returns a set of virtual machines that correspond to the filter criteria provided by the cmdlet parameters. For virtual machines with multiple NICs and multiple IP addresses, the IPAddress property of the VMGuest object contains all IP addresses of the virtual machine. The IP at position 0 is the primary IP address.

Syntax

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

Parameters

Required Parameter Name Type Position Features Description
optional
Datastore
StorageResource[] named
  • wildcards
  • pipeline
  • Specifies datastores or datastore clusters to filter the virtual machines associated with them. Passing values to this parameter through a pipeline is deprecated and will be removed in a future release.
    optional
    Location
    VIContainer[] named
  • wildcards
  • pipeline
  • Specifies vSphere container objects you want to search for virtual machines. Supported container object types are: ResourcePool, VApp, VMHost, Folder, Cluster, Datacenter.
    optional
    Name
    String[] named
  • wildcards
  • Specifies the names of the virtual machines you want to retrieve.
    optional
    NoRecursion
    SwitchParameter named Indicates that you want to disable the recursive behavior of the command.
    optional
    Server
    VIServer[] named
  • wildcards
  • Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.
    optional
    Tag
    Tag[] named
  • wildcards
  • Returns only the virtual machines that are associated with any of the specified tags.

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

    Parameters

    Required Parameter Name Type Position Features Description
    required
    Id
    String[] named
  • wildcards
  • Specifies the IDs of the virtual machines you want to retrieve.
    optional
    Server
    VIServer[] named
  • wildcards
  • Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.

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

    Parameters

    Required Parameter Name Type Position Features Description
    optional
    Name
    String[] named
  • wildcards
  • Specifies the names of the virtual machines you want to retrieve.
    optional
    Server
    VIServer[] named
  • wildcards
  • Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.
    optional
    Tag
    Tag[] named
  • wildcards
  • Returns only the virtual machines that are associated with any of the specified tags.
    optional
    VirtualSwitch
    VirtualSwitchBase[] named
  • wildcards
  • pipeline
  • When specified, the cmdlet returns only the virtual machines that have network adapters attached to the specified switches.

    -RelatedObject  <VmRelatedObjectBase[]>
    [CommonParameters]

    Parameters

    Required Parameter Name Type Position Features Description
    required
    RelatedObject
    VmRelatedObjectBase[] named
  • pipeline
  • Specifies objects to retrieve one or more vSphere VirtualMachine objects that are related to them. This parameter accepts vCloud CIVM and OMResource objects.

    Output

    VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine

    Examples


    Example 1

    Get-VM -Name MyVM*

    Retrieves all virtual machines whose names starting with "MyVM".

    Example 2

    $myDatastore = Get-Datastore -Name "MyDatastore"
    Get-VM -Datastore $myDatastore

    Retrieves all virtual machines that reside on the specified datastore.

    Example 3

    $myDatacenter = Get-Datacenter -Name "MyDatacenter"
    Get-VM -Location $myDatacenter

    Retrieves all virtual machines in the specified datacenter.

    Example 4

    $myVDSwitch = Get-VDSwitch -Name "MyVDSwitch"
    Get-VM -DistributedSwitch $myVDSwitch

    Retrieves all virtual machines connected to the specified distributed switch.

    Related Commands

    Feedback

    Was this page helpful?