You can use the simple PowerShell script below to check ESX server patching status from your Windows client. Requirements:
- .NET Framework 2.0
- PowerShell v1.0
- plink.exe (from the Putty download page) in your path
- An account and password to remotely connect over SSH and execute the command esxupdate query.
- Change the $servers array with your servers and also update the $account and $password variable.
- Keep the $patches array up-to-date with ESX patch names.
The script:
$patches=”ESX-2158032″,”ESX-1410076″,”ESX-1006511″,”ESX-9986131″,”ESX-8173580″,”ESX-6921838″,”ESX-2066306″,”ESX-6075798″,”ESX-5497987″,”ESX-3996003″,”ESX-2092658″,”ESX-2031037″,”ESX-1917602″,”ESX-1271657″,”ESX-9865995″,”ESX-6856573″,”ESX-6050503″,”ESX-5885387″,”ESX-5031800″,”ESX-3199476″,”ESX-9916286″,”ESX-9617902″,”ESX-8852210″,”ESX-8174018″,”ESX-7780490″,”ESX-7737432″,”ESX-5011126″,”ESX-3416571″,”ESX-1161870″,”ESX-2559638″,”ESX-2257739″,”ESX-1541239″
$servers=”server0″,”server1″
$account=”root”
$password=”password”$servers | % { $a=plink -pw $password $account@$_ “esxupdate query”
$server=$_
$patches | % {
$patch=$_
if( [regex]::match($a, $_).success ) {
$summary=”Installed”
}
else
{
$summary=”Not installed”
}new-object psobject |
add-member -pass NoteProperty Server $server |
add-member -pass NoteProperty Patch $patch |
add-member -pass NoteProperty Summary $summary}
}
Save the above script as a .ps1 file (e.g. c:\patch.ps1) and run it as follows:
./patch.ps1 | ft -groupby server
You will get an overview of all patches grouped by server.

2 Comments
A quick suggestion…
Put this line at the top of the script….
$password = Read-Host -assecurestring “Enter root password”
and remove this one…
$password=â€passwordâ€
This way you will be prompted for a password won’t have a text file sitting out there with your root password! *8)
Oops! A little too quick on the draw…
You also need to add this so it decrypts the password back so it can be used with plink.exe
Below this line:
$password = Read-Host -assecurestring “Enter root passwordâ€
Add these:
$Ptr=[System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($password)
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
Now it should all work….
*8)
Post a Comment