OpsaC - Operating as PowerShell code
published: January 4, 2024 author: Tinu tags: PowerShell categories: VMware
To list some properties of a ESXi Hosts, you need three steps.
For the login to the vCenter Server see vSphere REST API
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.
API Reference on VMware Developper Documentation, Data Structure HostSummary on VMware Developper Documentation,