Menu

Virtual Geek

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

Get VMware vCenter Appliance Version using Broadcom PowerCLI VCSA REST API

This PowerShell script uses VMware vCenter Server Rest API and shows VCSA (vCenter Server Appliance) version through the command line. Keeping track of your vCenter Server Appliance (VCSA) version is crucial for effective management and update. Simply provide your vCenter credentials, and the script handles the secure API interaction, offering a fast and efficient way to confirm your environment's current state. 

VMware vCenter VCSA Show installed version Update_Pending-queyr-time-powershell-rest-api-invoke-restmethod invoke-webrequest

Download this script Show-VCSACurrentVersion.ps1here or it is also available github.com for VMware vCenter Server monitoring

 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.com
# This script shows vCenter Server Appliance (VCSA) version using the vSphere REST API.
# This script 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
Check VCSA Upgrade Staging Progress using PowerShell vCenter REST API
Leveraging PowerShell to Stage VCSA Updates via vCenter REST API
Performing vCenter Offline Updates Via Your On-Prem Web Server Securely & Seamlessly
Retrieve VCSA vCenter Version with PowerShell REST API
PowerShell & VCSA: Checking for Pending & Latest Updates via REST API
Configure VCSA Update Web Repository Settings with PowerShell and REST API
Reset vCenter Server Appliance (VCSA) Forgotten Root Password Without Reboot
Delete VMware VCSA Management Schedule Backup Job using PowerShell
Modify Broadcom VCSA Management Schedule Backup Job using PowerCLI
Configure vCenter Server Appliance Schedule Backup With VMware.PowerCLI
Automating vCenter Server Appliance Backups with PowerShell On Demand
VMware Photon OS Remote SSH: Password Authentication Fix
Monitoring Dell Server Health Using RACADM CLI: Sensor Info from iDRAC
Fix CPU Support Error: Installing VMware ESXi 9 on Unsupported CPUs
Turn Your PowerShell Into a Web Server: Instantly Share Local HTML & Files!

Go Back

Comment

Blog Search

Page Views

13509487

Follow me on Blogarama