View Single Post
Old 01-01-2008   #3 (permalink)
IT Staff


 
 

Re: Grouping by patches using powergadget

anyone help ?


"IT Staff" <jkklim@xxxxxx> wrote in message
news:ONlDrt1SIHA.5128@xxxxxx
Quote:

> $computernames = get-content $pclist
> $patches = get-content $kblist
> foreach ($computer in $computernames)
> {
> $strQuery = "select * from win32_pingstatus where address = '" + $computer
> + "'"
> $wmi = Get-WmiObject -query $strQuery
>
> write-host -f green "Computer Name : " $computer.toupper() "`r"
> if ($wmi.statuscode -eq 0)
> {
> foreach ($kb in $patches)
> {
> $checkkb = Get-WmiObject Win32_QuickFixEngineering -computer $computer |
> where-object {$_.hotfixid -eq $kb}
>
> if ($checkkb)
> {
> write-host $kb "(found)" "`r"
> }
> else
> {
> write-host $kb "(Not found)" "`r"
> }
> }
> }
> else
> {write-host -f "Ping failed." "`r"}
> write-host "`r"
> }
> =======================================================
>
> i would like grouping to be :
>
> kb942763 = 5 computers found
> kb942763 = 1 computers not found
>
> kb928365 = 2 computers found
> kb928365 = 4 computers not found
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message
> news:B97FCFB9-51CF-401C-93C7-0AFA18DB6D6F@xxxxxx
Quote:

>> "IT Staff" <jkklim@xxxxxx> wrote in message
>> news:uB5S1ZTSIHA.2376@xxxxxx
Quote:

>>> foreach ($computer in $computernames)
>>> {
>>> foreach ($kb in $patches)
>>> {
>>> $checkkb = Get-WmiObject Win32_QuickFixEngineering -computer $computer
>>> | where-object {$_.hotfixid -eq $kb}
>>>
>>> if ($checkkb)
>>> {write-host $kb "(found)" "`r"}
>>> else
>>> {write-host -f red $kb "(Not found)" "`r"}
>>> }
>>> ===================================================================================
>>> the code works fine. i want to group by patches and count the machine
>>> that has the patch, and count computers that has no patch. (for each
>>> patch in the loop). How shld i approach the problem ?
>>>
>>> Once i group them , i will pipe out to powergadget
>>>
>>
>> You could try something like this:
>>
>> 40> $computers | foreach {$computer=$_;gwmi
>> Win32_QuickFixEngineering -computer $_ | select
>> HotFixID,@{n='Computer';e={$
>> computer}}} | group {$kbs -contains $_.HotFixID}
>>
>> Count Name Group
>> ----- ---- -----
>> 70 False {{AC76BA86-7AD7-0000-2550-7A8C40000000},
>> {D93F9C7C-AB57-44C8-BAD6-1494674BCAF7}, {89...
>> 2 True {KB938194, KB942624}
>>
>> False means not patched and true means patched.
>>
>> --
>> Keith
>
>

My System SpecsSystem Spec