Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

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

published: January 4, 2024 author: Tinu tags: PowerShell categories: VMware


Table of Contents

ESXi Hosts

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

  • vCenter Login
  • Get HostSummary of the specified ESXi Host by name

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
if(!$esxByName){
    Write-Warning "Could not find any ESXi Host with name $esxName"
    break
}
#endregion

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,


← Previous Post [ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →