If you have a relatively small HCX deployment, for example a legacy vCenter environment connected to a single VMC on AWS SDDC, lifecycle management of the various HCX components is quite straight forward; you could simply log into each manager (2 in this case) and have a look in the UI, or check the VC plugin version.
Things get a little more difficult if we are migrating from VCF 3.x into VCF 4.x. where multiple Workload Domains (WLD) are involved. Each WLD has its own vCenter Server, and since HCX to vCenter Server is a 1:1 mapping, has its own HCX Manager. Logging onto 10 or more HCX Managers just to check their version is going to take some time.
We can use PowerCLI with the HCX modules to get the HCX Appliance version (Get-HCXAppliance) once connected to a HCX server however there is no way to get the Manager (Cloud or Enterprise) version.
Thankfully, the /service/inventory/resourcecontainer/list API does give this information, along with a lot of other detail.
For those wishing to automate this using PowerCLI, you can use Invoke-Webrequest along with an authentication token to get the information. William Lam originally did a HCX blog covering HCX API and PowerCLI, and I used his Github page to butcher a script which will loop around an input CSV and return all HCX manager versions along with the vCenter version to which they are registered with. This is useful if you manage a larger fleet of appliances in order to maintain some form of Lifecycle management. Of course if your automation mainly uses API then you can incorporate that instead.
The script could be made into a function and while it’s quick and doesn’t have a great deal in the way of error handling, it works.
# ===========================================================================
# Author: William Lam's original HCX scripts https://github.com/lamw/VMware.HCX
# Date: 01/02/2022
# Organization: VMware
# ===========================================================================
# This script will loop through HCX servers in the input CSV and retrieve HCX Name, Version, plus the vCenter Name and Version it is registered it.
# It assumes that the $username and $password variables have the correct privs.
# It also assumes DNS is working, and each HCX manager can be reached.
$csv = Import-Csv -Header 'ServerName' "<csv_path_here>"
$csv | ForEach-Object {
$server = $_.ServerName
$Username = "<username>"
$Password = "<password>"
$payload = @{
"username" = $Username
"password" = $Password
}
$body = $payload | ConvertTo-Json
$hcxLoginUrl = "https://$server/hybridity/api/sessions"
if($PSVersionTable.PSEdition -eq "Core") {
$results = Invoke-WebRequest -Uri $hcxLoginUrl -Body $body -Method POST -UseBasicParsing -ContentType "application/json" -SkipCertificateCheck
} else {
$results = Invoke-WebRequest -Uri $hcxLoginUrl -Body $body -Method POST -UseBasicParsing -ContentType "application/json"
}
if($results.StatusCode -eq 200) {
$hcxAuthToken = $results.Headers.'x-hm-authorization'
$headers = @{
"x-hm-authorization"="$hcxAuthToken"
"Content-Type"="application/json"
"Accept"="application/json"
}
$global:hcxConnection = new-object PSObject -Property @{
'Server' = "https://$server/hybridity/api";
'headers' = $headers
}
} else {
Write-Error "Failed to connect to HCX Manager, please verify your vSphere SSO credentials"
}
$HCXconfigUrl = $global:hcxConnection.Server + "/service/inventory/resourcecontainer/list"
if($PSVersionTable.PSEdition -eq "Core") {
$HCXversionRequests = Invoke-WebRequest -Uri $HCXconfigUrl -Method POST -Headers $global:hcxConnection.headers -Body $body -UseBasicParsing -SkipCertificateCheck
} else {
$HCXversionRequests = Invoke-WebRequest -Uri $HCXconfigUrl -Method POST -Headers $global:hcxConnection.headers -Body $body -UseBasicParsing
}
$HCXversionData = ($HCXversionRequests.content | ConvertFrom-Json).data.items
#You can edit the below values based on $HCXversionData output to your requirements
$tmp = [pscustomobject] @{
HCXName = $HCXversionData.endpointName;
HCXVersion = $HCXversionData.endpoint.version;
vCenterName = $HCXversionData.name;
vCenterVersion = $HCXversionData.version;
}
$tmp
}
Example output is below.
You can customise line 55 to include parts of the result which you are interested in.
PowerCLI is not a great strength of mine, without William’s original work it would have taken me much longer to get something working. Hopefully it will help you.