< Back

Get-VM

Sun Jan 19, 2020 6:54 pm

NAME 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>]





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

-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.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? true



-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.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? true



-Location <VIContainer[]>

Specifies vSphere container objects you want to search for virtual machines. Supported container object types

are: ResourcePool, VApp, VMHost, Folder, Cluster, Datacenter.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? true



-Name <String[]>

Specifies the names of the virtual machines you want to retrieve.



Required? false

Position? 1

Default value None

Accept pipeline input? False

Accept wildcard characters? true



-NoRecursion [<SwitchParameter>]

Indicates that you want to disable the recursive behavior of the command.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? 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.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



-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.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? true



-Tag <Tag[]>

Returns only the virtual machines that are associated with any of the specified tags.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? true



-VirtualSwitch <VirtualSwitchBase[]>

When specified, the cmdlet returns only the virtual machines that have network adapters attached to the

specified switches.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? true



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

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.



-------------------------- 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 LINKS

Online Version: https://code.vmware.com/doc/preview?id= ... et-VM.html

Remove-VM

New-VM

Set-VM

Move-VM

Start-VM

Stop-VM

Suspend-VM

Restart-VM