PowerCLI Reference

Get-VM

Synopsis

This cmdlet retrieves the virtual machines on a vCenter Server system.

Syntax

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

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

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

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

Related Commands

Online Version
Remove-VM
New-VM
Set-VM
Move-VM
Start-VM
Stop-VM
Suspend-VM
Restart-VM

Detailed Description

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.

Parameters

NameTypeDescriptionRequired?Pipeline InputDefault Value
NameString[]Specifies the names of the virtual machines you want to retrieve.falseFalse
DatastoreStorageResource[]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.falseTrue (ByValue)
IdString[]Specifies the IDs of the virtual machines you want to retrieve.


Note: When a list of values is specified for the Id parameter, the returned objects would have an ID that matches exactly one of the string values in that list.
trueFalse
LocationVIContainer[]Specifies vSphere container objects you want to search for virtual machines. Supported container object types are: ResourcePool, VApp, VMHost, Folder, Cluster, Datacenter.falseTrue (ByValue)
NoRecursionSwitchParameterIndicates that you want to disable the recursive behavior of the command.falseFalse
RelatedObjectVmRelatedObjectBase[]Specifies objects to retrieve one or more vSphere VirtualMachine objects that are related to them. This parameter accepts vCloud CIVM and OMResource objects.trueTrue (ByValue)
ServerVIServer[]Specifies the vCenter Server systems on which you want to run the cmdlet. If no 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.falseFalse
TagTag[]Returns only the virtual machines that are associated with any of the specified tags.falseFalse
VirtualSwitchVirtualSwitchBase[]When specified, the cmdlet returns only the virtual machines that have network adapters attached to the specified switches.falseTrue (ByValue)

Return Type

Zero or more VirtualMachine objects

Notes

The NetworkName property, which is of type NicInfo and is accessed through the Vm.Guest.Nics property, is deprecated. When a virtual machine is part of a vApp, the Folder and FolderId properties are $null.

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.


Copyright © VMware, Inc. All rights reserved.