Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Search for installed patches

310 views
Skip to first unread message

joeroc

unread,
Dec 30, 2009, 9:54:02 PM12/30/09
to

I've been looking for a quick way to use powershell to display a list of
installed hotfixes in a way similiar to the running the systeminfo command.
I've found the following info on Tim Mintner's blog but this displays all
info as it pertains to installed patches:

$wu = new-object -com "Microsoft.Update.Searcher"
$totalupdates = $wu.GetTotalHistoryCount()
$wu.QueryHistory(0,$totalupdates)

I was able to use the following to use group-object to filter most of the info

$wu.QueryHistory(0,$totalupdates) | group-object title

I still would like to parse through this and only display the KB#### alone.

I also found the following command that would query for a specific hotfix
and from the output displays a hotfixid category.

Get-WmiObject -Query 'select * from Win32_QuickFixEngineering' | where
{$_.HotFixID -eq 'KB956391'}

Is there anyway to combine the two together to display only a list of
installed hotfixes and\or patches\critical updates?

Thanks,

joe

Marco Shaw [MVP]

unread,
Dec 31, 2009, 7:00:38 AM12/31/09
to
How exactly do you want to see this output? Just a list of KBs? I don't
follow how you want to integrate the Get-WmiObject output... You want to
query for specific KBs, and have that show in your list if installed?

What do you want outputted if there isn't an associated KB? For example,
here's one title:
Office Live add-in 1.4


"joeroc" <joe...@discussions.microsoft.com> wrote in message
news:E7F13834-4340-483E...@microsoft.com...

joeroc

unread,
Dec 31, 2009, 8:34:01 AM12/31/09
to
I would like to first be able to see just a concise list of installed KB's
(#'s only) and display it in Powershell. Then include as an external
parameter to the powershell script the option to include specific and\or
multiple KB's to look for and confirm thier status. If none are found then
it would default to displaying the whole list. If found the results would
display only the one's it was able to confirm.

"Marco Shaw [MVP]" wrote:

> .
>

Joe Morris

unread,
Dec 31, 2009, 9:46:13 AM12/31/09
to
"joeroc" <joe...@discussions.microsoft.com> wrote:
>
> I've been looking for a quick way to use powershell to display a list of
> installed hotfixes in a way similiar to the running the systeminfo
> command.

[...]

> I still would like to parse through this and only display the KB####
> alone.
>
> I also found the following command that would query for a specific hotfix
> and from the output displays a hotfixid category.
>
> Get-WmiObject -Query 'select * from Win32_QuickFixEngineering' | where
> {$_.HotFixID -eq 'KB956391'}
>
> Is there anyway to combine the two together to display only a list of
> installed hotfixes and\or patches\critical updates?

Why not a slight modification of your own WMI example? Or am I missing what
you're looking for?


Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach
{$_.hotfixid}


To restrict that to a specific KB entry reinstate the "where" clause in the
pipeline as used in your WMI example:


Get-WmiObject -query 'select * from win32_quickfixengineering' | where
{$_.hotfixid -eq "KB973525"} | foreach {$_.hotfixid}.


(both of the sample commands above are a single line which will probably be
broken in two by newsreaders)

Joe Morris


joeroc

unread,
Jan 2, 2010, 9:03:01 PM1/2/10
to
After watching the TechNet Video "Writing Scripts with Powershell" I was able
to edit the previous code to display a formated list of installed KB's and if
I append to the script a specific KB, if installed would return a value of
1. Here is the code:

$hotfix = get-wmiobject query "select * from win32_quickfixengineering" |
sort hotfixid
$kb = $hotfix | format-table @{label="HotFixId";expression={$_.hotfixid}}
$a=$args.length
if($a -eq 0)
{$kb)
else{$hotfix | where{$_.hotfixid=$args{0}}

How do I now query for more then one KB simultaneously and if installed
subsititute the 1 for the KB name in green and if not installed kb name in
red?

Marco Shaw [MVP]

unread,
Jan 3, 2010, 4:09:21 PM1/3/10
to
> How do I now query for more then one KB simultaneously and if installed
> subsititute the 1 for the KB name in green and if not installed kb name in
> red?

So you want to do something like this:

PS>./my_script.ps1 KB1 KB2 KB3

Then, has your script output like this:
KB1 (green because it is installed)
KB2 (red because it is not installed)
etc.

You can't change the colors line-by-line of Format-Table output, but you can
use Write-Host though to change the foreground and background colors.

Marco

joeroc

unread,
Jan 3, 2010, 8:29:01 PM1/3/10
to
That's exactly what I'm trying to accomplish. How would I be able to
configure the else{$hotfixid | where{$_.hotfixid=$args[0]}} to include KB2,
KB3 etc?

"Marco Shaw [MVP]" wrote:

> .
>

IT Staff

unread,
Jan 3, 2010, 9:36:30 PM1/3/10
to
# Function : to check for A LIST OF DEFINED kbxxxx patches on remote
machines
# use optional powergadget charts

param($pclist,$kblist,$powergadget)
function Usage {
@'
Syntax:
powershell.exe .\kblist.ps1 pclist.txt kblistings.txt <Powergadget Filename>

-pclist.txt : Specifies a MANDATORY filename that contains machine names
-kblist.txt : Specifies a MANDATORY filename that contains patches names eg
KBXXXXXX
-Powergadget Filename : Specifies a OPTIONAL Powergadget filename.
'@
exit 1
}

if (!$pclist -or !$kblist)
{
clear-host
Usage
}

# $erroractionpreference = "SilentlyContinue"
clear-host

$filepath = "c:\results.txt"
[system.io.file]::delete($filepath)


#check for existence of CORRECT filename
$pclist_exist = [System.IO.File]::Exists($pclist)
$kblist_exist = [System.IO.File]::Exists($kblist)
if (!$pclist_exist) {write-host "$pclist filename does not reside in current
directory.";break}
if (!$kblist_exist) {write-host "$kblist filename does not reside in current
directory.";break}

if ($powergadget)
{
# check for powergadget file name
$powergadget_exist = [System.IO.File]::Exists($powergadget)
if (!$powergadget_exist) {write-host "$powergadget filename does not reside
in current directory.";break}
}

$computernames = get-content $pclist
$patches = get-content $kblist
$hotfix = @{}

foreach ($kb in $patches)
{
write-host -f green "Patch:" $kb.toupper() "`r"

write `r | out-file -filepath $filepath -append
"Patch: " + $kb.toupper() | out-file -filepath $filepath -append

foreach ($computer in $computernames)
{
$found=0
$ping=0

$strQuery = "select * from win32_pingstatus where address = '" + $computer
+ "'"
$wmi = Get-WmiObject -query $strQuery

if ($wmi.statuscode -eq 0)
{
$ping=1
$checkkb = Get-WmiObject Win32_QuickFixEngineering -computer $computer |
where-object {$_.hotfixid -eq $kb}
if ($checkkb)
{
write-host $computer "(found) `r"
"$computer (found)" | out-file -filepath $filepath -append
$found=1
}
else
{
write-host $computer "(Not found) `r"
"$computer (Not found)" | out-file -filepath $filepath -append
}
}
else
{
write-host "$computer Ping Failed. `r"
"$computer Ping Failed" | out-file -filepath $filepath -append
}

$obj = 1 | select
@{n="Computer";e={$computer}},@{n="Found";e={$found}},@{n="PingOK";e={$ping}}
$hotfix["$kb"] += @($obj)
}
}

write-host `n

if ($powergadget)
{
# display using powergadget
Add-PSSnapin PowerGadgets

$hotfix.keys | select @{n="Patch";e={$_}},
@{n="Found";e={@($hotfix.$_ |where{$_.Found}).Count}},
@{n="Not Found";e={@($hotfix.$_).count - @($hotfix.$_
|where{$_.Found}).Count}} | out-chart -template $powergadget

}
else
{
# display on screen
$a = $hotfix.Keys | foreach {
$found = @($hotfix.$_ | where {$_.Found}).Count
$Pingsuccess = @($hotfix.$_ | where {$_.pingok}).Count
$notfound = @($hotfix.$_).Count - $found
$pingfail = @($hotfix.$_).Count - $pingsuccess
"$_ found in $found machines, Not Found: $notfound machines of which Ping
Failed in $pingfail machines"}

write `r | out-file -filepath $filepath -append
$a | out-file -filepath $filepath -append
$a
}

write-host "`nDetails written to $filepath"


Rob

unread,
Mar 19, 2010, 1:56:02 PM3/19/10
to
Question for IT Staff:

This works great but I would like to view the output on a HTML file. This
way I can check via a website the report. I am still learning Powershell, so
would you be able explain how i can take your script here and write it to a
column\table formatted html file.. I would really appreciate it..

Thanks, Rob

"IT Staff" wrote:

> .
>

rayala

unread,
Mar 19, 2010, 2:05:16 PM3/19/10
to

Question for IT Staff:

This works great but I would like to view the output on a HTML file.
This
way I can check via a website the report. I am still learning
Powershell, so
would you be able explain how i can take your script here and write it
to a
column\table formatted html file.. I would really appreciate it..

Thanks, Rob


--
rayala

0 new messages