VMware Cloud Community
vin01
Expert
Expert
Jump to solution

Invoke vmscript to get windows hotfix information on multiple versions

Hi

I am trying to fetch windows hotfix installed status for multiple versions.Here the problem is the Hotfix number is not same to all the versions of windows. -Like (kb4056897 is for windows 2k8r2 which is not same for win2k12)

with the below script I can able get only one hotfix details at once. -Like (For kb4056897 it will invoke the script for all the windows machines and write the output for only 2k8r2 as this hotfix belongs to 2k8r2). So is there any possibility to pass multiple hotfix numbers in one variable ($hotfix=kb4056897,kb4056894 )and pass this cmd (Get-WmiObject -Class "win32_quickfixengineering") and search the hotfix numbers which we given in $hotfix and write the output.

$script = @'

$hotfixinfo=Get-WmiObject -Class "win32_quickfixengineering" |?{$_.HotFixID -eq "KB4049011"}|%{"$($_.HotFixID) is installed on $($_.InstalledOn)"}

$hotfixinfo

'@

Invoke-VMScript -VM $vm.name -GuestCredential $password1  -ScriptText $script -ScriptType Powershell -ErrorAction Stop | Select -ExpandProperty ScriptOutput

Regards Vineeth.K
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

$hotfix = "KB4056897", "KB4056894", "KB4100480", "KB4088878", "KB4049011", "KB4088877", "KB4056898",

    "KB4088879", "KB4056895", "KB4056890", "KB4056892", "KB4056897", "KB4056894", "KB4100480", "KB4088878",

    "KB4088877", "KB4056898", "KB4088879", "KB4056895", "KB4056893", "KB4056888", "KB4056890", "KB4056891",

    "KB4056892", "KB4088782"

$hotfixinfo = "No hotfix found!" 

$fixes = Get-WmiObject -Class "win32_quickfixengineering" |

    where{$hotfix -contains $_.HotFixID} |

    Select -ExpandProperty HotFixID

if($fixes){

    $hotfixinfo = "$($fixes -join ',') installed"

}

$hotfixinfo


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$script = @'

$hotfix = 'kb4056897''kb4056894'

$hotfixinfo = "No hotfix found!"

foreach($fix in $hotfix){

    Get-WmiObject -Class "win32_quickfixengineering" |

        where{$_.HotFixID -eq $fix} | %{

            $hotfixinfo = "$($_.HotFixID) is installed on $($_.InstalledOn)"

            break

        }

$hotfixinfo

'@


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

vin01
Expert
Expert
Jump to solution

Yes this is working but one more step which would be helpful to get accurate report. For few versions of OS two hot fix's are installed which i mentioned in $hotfix. So is it possible to write that two installed hotfix names in output variable $hotfixinfo.

$hotfix = "KB4056897", "KB4056894", "KB4100480", "KB4088878", "KB4049011", "KB4088877", "KB4056898", "KB4088879", "KB4056895", "KB4056890", "KB4056892", "KB4056897", "KB4056894", "KB4100480", "KB4088878", "KB4088877", "KB4056898", "KB4088879", "KB4056895", "KB4056893", "KB4056888", "KB4056890", "KB4056891", "KB4056892", "KB4088782"

$hotfixinfo = "No hotfix found!"

foreach($fix in $hotfix){

    Get-WmiObject -Class "win32_quickfixengineering" |

        where{$_.HotFixID -eq $fix} | %{

            $hotfixinfo = "$($_.HotFixID) is installed on $($_.InstalledOn)"

            break

        }

}

$hotfixinfo

KB4049011 is installed on 01/22/2018 00:00:00

But "KB4088782" is also installed in that machine.so i need both the kb's info in $hotfixinfo.

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$hotfix = "KB4056897", "KB4056894", "KB4100480", "KB4088878", "KB4049011", "KB4088877", "KB4056898",

    "KB4088879", "KB4056895", "KB4056890", "KB4056892", "KB4056897", "KB4056894", "KB4100480", "KB4088878",

    "KB4088877", "KB4056898", "KB4088879", "KB4056895", "KB4056893", "KB4056888", "KB4056890", "KB4056891",

    "KB4056892", "KB4088782"

$hotfixinfo = "No hotfix found!" 

$fixes = Get-WmiObject -Class "win32_quickfixengineering" |

    where{$hotfix -contains $_.HotFixID} |

    Select -ExpandProperty HotFixID

if($fixes){

    $hotfixinfo = "$($fixes -join ',') installed"

}

$hotfixinfo


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

0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks LucD. Its working.Smiley Happy

Regards Vineeth.K
0 Kudos