Ik wilde weten of een bepaald KB nummer was geïnstalleerd op mijn VM’s. Dit wilde ik natuurlijk niet met het handje nakijken en heb hiervoor een script bij elkaar geraapt.
Het onderstaande script kun je gebruiken in een VMware VI omgeving.
#Add-PSSnapIn VMware.VimAutomation.Core
# Connect to vCenter $VC = Connect-VIServer (Read-Host "Enter vCenter server")
# Enter the KB# $HotFixID = (Read-Host "Enter KB#") Write-Host
# Get all VM’s with powerstate = PoweredOn $VMS = Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Sort Name
ForEach ($VM in $VMS)
{ # Process only Windows Server VM’s if ($VM.Guest.OSFullName -match "Microsoft Windows Server*") { # Get all the info using WMI $results = get-wmiobject -class "Win32_QuickFixEngineering" -namespace "root\CIMV2" -ComputerName $VM # Loop through $results and look for a match then output to screen foreach ($objItem in $results) { # Do the match if ($objItem.HotFixID -match $HotFixID) { write-host $objItem.CSName write-host "Hotfix "$HotFixID" installed" write-host } } } } # Disconnect from vCenter Disconnect-VIServer -Confirm:$False
|
Zodra je het script start, word er gevraagd naar de vCenter server en het KB nummer wat je wilt nakijken.
De volgende output wordt gegenereerd:
Je kunt het onderstaande script gebruiken in een omgeving zonder VI3:
# Get content $computers = get-content c:\computers.txt
# Get all the info using WMI $results = get-wmiobject -class “Win32_QuickFixEngineering” -namespace “root\CIMV2″ -computername $computers
# Loop through $results and look for a match then output to screen foreach ($objItem in $results) { if ($objItem.HotFixID -match “KB932168″) { write-host $objItem.CSName write-host “Hotfix KB932168 installed” write-host } }
|
Source: http://techittome.wordpress.com/2007/04/12/windows-powershell-script-to-check-for-specific-hotfix/
Like this:
Like Loading...
Related
One thought on “Powershell: Check if KB patch is installed”