Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Retrieve VCSA vCenter Version with PowerShell REST API

This PowerShell helps to fetch the current version of  VCSA (VMware vCenter Server Appliance). This information is useful while automating VCSA upgrade, It is fetched used from VCSA REST API.

Screenshot of a PowerShell console running 'Show-VCSACurrentVersion.ps1'. The output shows 'Appliance Update Status:', 'Latest Query Time: 08/04/2025 16:00:56', 'Current State: UP_TO_DATE', and 'Installed Version: 8.0.0.300400'.

In the vCenter Server Management portal you can see the Version in the update.

Screenshot of the vCenter Server Management interface, 'Update' tab. It shows 'Current version details' as 8.0.0.400. Below 'Available updates', an update for version 8.0.0.500 is listed as 'Staged', with 'Type: Fix', 'Release Date: Apr 10, 2025', 'Reboot required: Yes', and 'Severity: Critical'.

You can download this script Show-VCSACurrentVersion.ps1 here or it is also available on github.com.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# vCenter Update Script
# created by vCloud-Lab.lab
# This script checks current version on a vCenter Server using the REST API.
# Requires PowerShell 7 or newer

param (
    [string]$vcServer = "marvel.vcloud-lab.com",
    [string]$vcUser = "[email protected]",
    [string]$vcPass = "Computer@123"
)

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

# Get session ID using username/password
function Get-VCenterSession {
    $authUri = "https://$vcServer/rest/com/vmware/cis/session"
    $authBytes = [System.Text.Encoding]::UTF8.GetBytes("${vcUser}:${vcPass}")
    $authHeader = "Basic " + [System.Convert]::ToBase64String($authBytes)

    $headers = @{
        "Authorization" = $authHeader
        "Content-Type"  = "application/json"
    }

    $response = Invoke-RestMethod -Uri $authUri -Method Post -Headers $headers -SkipCertificateCheck
    return $response.value
}

# Get appliance update status
function Get-ApplianceUpdateStatus {
    param (
        [string]$vcServer,
        [string]$sessionId
    )

    $uri = "https://$vcServer/api/appliance/update"
    $headers = @{ "vmware-api-session-id" = $sessionId }

    try {
        $result = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -SkipCertificateCheck
        Write-Host "🔍 Appliance Update Status:"
        Write-Host "Latest Query Time : $($result.latest_query_time)"
        Write-Host "Current State      : $($result.state)"
        Write-Host "Installed Version  : $($result.version)"
    }
    catch {
        Write-Warning "⚠️ Failed to retrieve appliance update status: $($_.Exception.Message)"
    }
}

# --- MAIN ---
try {
    $session = Get-VCenterSession
    if (-not $session) { throw "❌ Could not authenticate with vCenter." }

    Get-ApplianceUpdateStatus -vcServer $vcServer -sessionId $session
}
catch {
    Write-Error "❌ ERROR: $($_.Exception.Message)"
}
finally {
    if ($session) {
        $logoutUri = "https://$vcServer/rest/com/vmware/cis/session"
        Invoke-RestMethod -Method Delete -Uri $logoutUri -Headers @{ "vmware-api-session-id" = $session } -SkipCertificateCheck
        Write-Host "🔒 Session logged out."
    }
}

Useful Articles
Install VMware VCSA Patch Upgrade using PowerCLI vCenter REST API
Configure, Manage and Assign License Settings for VMware vCenter Server and ESXi
Administrating licenses in vSphere client
Assign vSAN licenses in vSphere client
Solved: VMware Snapshots Virtual Machines disks consolidation is needed
Performing vCenter Offline Updates Via Your On-Prem Web Server Securely & Seamlessly
Configure VCSA Update Web Repository Settings with PowerShell and REST API
Reset vCenter Server Appliance (VCSA) Forgotten Root Password Without Reboot
How to install Ansible on Linux for vSphere configuration
Using Ansible for Managing VMware vsphere Infrastructure

Go Back

Comment

Blog Search

Page Views

13900392

Archive

Follow me on Blogarama