Kaicy0443
Contributor
Contributor

How to get Windows last update with PowerCLI for Servers from a VCenter?

I want to use powerCLI to check the last update date of Windows Update for servers in VCenter. Im rlly stucked and dont know how to do it. can someone help me?

Reply
0 Kudos
LucD
Leadership
Leadership

You will have to use a command in the Guest OS for that.
Something like for example

Get-WmiObject win32_quickfixengineering |
Sort-Object -Property installedon -Descending |
Select-Object -First 1 -Property installedon



You can use the Invoke-VMScript cmdlet to run such a Guest OS command, provided all the prerequisites are fulfilled.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Kaicy0443
Contributor
Contributor

hi LucD, how does it work with invoke-vmscript? All servers of the vcenter have the VMware tools installed. I just want to compare a script with that it creates a list in case the windows update date is older than 90 days
thank you very much!

Reply
0 Kudos
LucD
Leadership
Leadership

Have a look at the examples on the Invoke-VMScript help page.
Also, search in this community on Invoke-VMScript, there are ample snippets available.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Kaicy0443
Contributor
Contributor

can it be that if I use invoke-vmscript, but the result of it is not the same as I insert the commands on server itself?

fe:
i used this script for my server file11:

# Get the latest Quick Fix data
$LatestQuickFix = Get-WmiObject win32_quickfixengineering |
Sort-Object -Property installedon -Descending |
Select-Object -First 1

$InstallDate = $LatestQuickFix.installedon.ToString("MM/dd/yyyy")


$Script = "Write-Host 'Latest Quick Fix Installed On: $InstallDate'"


$VMName = "file11"


$result = Invoke-VMScript -VM $VMName -ScriptText $Script -GuestUser $vCenterUser -GuestPassword $vCenterPass

 

 

the $result showed me:
Latest Quick Fix Installed On: 09.26.2023

but if i do this on my server, 

the result:
InstalledOn

--------------

05.10.2023 00:00:00

 

Im new in powerCLI, can u help me a bit?



Reply
0 Kudos
LucD
Leadership
Leadership

Perhaps try like this.

To make sure, the $vCenterUser and $vCenterPass variables contain the credentials for the Guest OS on the VM named 'file11'?

# Get the latest Quick Fix data
$script = @'
$LatestQuickFix = Get-WmiObject win32_quickfixengineering |
   Sort-Object -Property installedon -Descending |
   Select-Object -First 1

$LatestQuickFix.installedon.ToString("MM/dd/yyyy")
'@

$VMName = "file11"
$result = Invoke-VMScript -VM $VMName -ScriptText $Script -GuestUser $vCenterUser -GuestPassword $vCenterPass

$result.ScriptOutput
 

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos