Get-VMHost

This cmdlet retrieves the hosts on a vCenter Server system. Returns a set of hosts that correspond to the filter criteria provided by the cmdlet parameters. To specify a server different from the default one, use the Server parameter. When working directly on an ESX host, the Name property of the returned VMHost object contains either the DNS name or the IP of the ESX host, depending on which of them was specified when connecting with Connect-VIServer.

Syntax

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

Parameters

Required Parameter Name Type Position Features Description
optional
Datastore
StorageResource[] named
  • wildcards
  • pipeline
  • Specifies the datastores or datastore clusters to which the hosts that you want to retrieve are associated. 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 the vSphere container objects (such as folders, datacenters, and clusters) you want to search for hosts.
    optional
    Name
    String[] named
  • wildcards
  • Specifies the names of the hosts 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
    State
    VMHostState[] named Specifies the state of the hosts you want to retrieve. The valid values are Connected, Disconnected, NotResponding, and Maintenance.
    optional
    Tag
    Tag[] named
  • wildcards
  • Returns only the virtual machine hosts 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 hosts 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.

    [-DistributedSwitch  <DistributedSwitch[]>]
    [-Name  <String[]>]
    [-Server  <VIServer[]>]
    [-Tag  <Tag[]>]
    [CommonParameters]

    Parameters

    Required Parameter Name Type Position Features Description
    optional
    DistributedSwitch
    DistributedSwitch[] named
  • wildcards
  • pipeline
  • Filters the available hosts by the virtual switches they are connected to.
    optional
    Name
    String[] named
  • wildcards
  • Specifies the names of the hosts 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 machine hosts that are associated with any of the specified tags.

    -RelatedObject  <VMHostRelatedObjectBase[]>
    [CommonParameters]

    Parameters

    Required Parameter Name Type Position Features Description
    required
    RelatedObject
    VMHostRelatedObjectBase[] named
  • pipeline
  • Specifies objects to retrieve one or more VMHost objects that are related to them. This parameter accepts OMResource objects.

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

    Parameters

    Required Parameter Name Type Position Features Description
    optional
    Datastore
    StorageResource[] named
  • wildcards
  • pipeline
  • Specifies the datastores or datastore clusters to which the hosts that you want to retrieve are associated. 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 the vSphere container objects (such as folders, datacenters, and clusters) you want to search for hosts.
    optional
    Name
    String[] named
  • wildcards
  • Specifies the names of the hosts you want to retrieve.
    optional
    NoRecursion
    SwitchParameter named Indicates that you want to disable the recursive behavior of the command.
    optional
    ResourcePool
    ResourcePool[] named
  • wildcards
  • Specifies resource pools associated with the hosts 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 machine hosts that are associated with any of the specified tags.
    optional
    VM
    VirtualMachine[] named
  • wildcards
  • pipeline
  • Specifies virtual machines whose hosts you want to retrieve.

    Output

    VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost

    Examples


    Example 1

    Get-VMHost -Location MyDatacenter

    Retrieves all hosts in the specified datacenter.

    Example 2

    $MyVM = Get-VM -Name MyVM
    Get-VMHost -VM $MyVM

    Retrieves the host on which the specified virtual machine runs.

    Example 3

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

    Retrieves all hosts associated with the specified vSphere distributed switch.

    Related Commands

    Feedback

    Was this page helpful?