$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
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...
"Marco Shaw [MVP]" wrote:
> .
>
[...]
> 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
$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?
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
"Marco Shaw [MVP]" wrote:
> .
>
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"
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:
> .
>
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