Syntax
Get-VM [[-Name] <String[]>] [-Datastore <StorageResource[]>] [-Location <VIContainer[]>] [-NoRecursion] [-Server <VIServer[]>] [-Tag <Tag[]>] [<CommonParameters>]Related Commands
Online VersionDetailed 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
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Name | String[] | Specifies the names of the virtual machines you want to retrieve. | false | False | |
Datastore | StorageResource[] | 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. | false | True (ByValue) | |
Id | String[] | 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. | true | False | |
Location | VIContainer[] | Specifies vSphere container objects you want to search for virtual machines. Supported container object types are: ResourcePool, VApp, VMHost, Folder, Cluster, Datacenter. | false | True (ByValue) | |
NoRecursion | SwitchParameter | Indicates that you want to disable the recursive behavior of the command. | false | False | |
RelatedObject | VmRelatedObjectBase[] | Specifies objects to retrieve one or more vSphere VirtualMachine objects that are related to them. This parameter accepts vCloud CIVM and OMResource objects. | true | True (ByValue) | |
Server | VIServer[] | 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. | false | False | |
Tag | Tag[] | Returns only the virtual machines that are associated with any of the specified tags. | false | False | |
VirtualSwitch | VirtualSwitchBase[] | When specified, the cmdlet returns only the virtual machines that have network adapters attached to the specified switches. | false | True (ByValue) |
Return Type
Zero or more VirtualMachine objectsNotes
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.