Tinus EngOps Wiki


OpsaC - Operating as PowerShell code



PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

API ESXi Hosts

tags: PowerShell - News categories: VMware

Table of Contents

ESXi Hosts

To list some properties of a ESXi Hosts, you need three steps.

vCenter Login

For the login to the vCenter Server see vSphere REST API

Get HostSummary of the specified ESXi Host by name

To get the identifier of an ESXi Host, you have to provide the name of the ESXi Host and set it to the filter in the API Url.

#region Get the specified ESXi Host by name
$esxName = 'tunix666.companx.local'
$Properties = @{
    Uri             = "https://$($vCenterServer)/api/vcenter/host?names=$($esxName)"
    Method          = 'Get'
    Headers         = $ApiSessionHeaders
    UseBasicParsing = $true
    ContentType     = 'application/json'
    ErrorAction     = 'Stop'
$esxByName = Invoke-RestMethod @Properties
    Write-Warning "Could not find any ESXi Host with name $esxName"

Output HostSummary as PSCustomObject:

host             : host-1024
name             : tunix666.companx.local
connection_state : CONNECTED
power_state      : POWERED_ON

If you need the HostSummary of all ESXi Hosts, change the API Url to https://$($vCenterServer)/api/vcenter/host. This will returns information about at most 2500 visible ESXi Hosts in vCenter.

See also

API Reference on VMware Developper Documentation, Data Structure HostSummary on VMware Developper Documentation,

[ Top ] [ Blog ]