vSphere PowerCLI Reference

Get-VM

Synopsis

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

Syntax

Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] [-Datastore <StorageResource[]>] [-Location <VIContainer[]>] [-Tag <Tag[]>] [-NoRecursion] [<CommonParameters>]
Get-VM [[-Name] <String[]>] [-Server <VIServer[]>] [-VirtualSwitch <VirtualSwitchBase[]>] [-Tag <Tag[]>] [<CommonParameters>]
Get-VM [-Server <VIServer[]>] -Id <String[]> [<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.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 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.

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 © 1998 - 2014 VMware, Inc. All rights reserved.