header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Checking Hotfixes on Servers
Last Post 03 Oct 2008 05:53 PM by SynJunkie. 6 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
02 Oct 2008 10:09 AM  

Hi Guys.

I could really use some help on a script I am working on.  I am trying to query a bunch of servers for a particular hotfix and return whether it is installed or not.

Unfortunately I can't quite get this working and I'm struggling to see where I am going wrong. each time I run the script it prompts me for the server list, then for the Hotfix KB number but then returns that the hotfix is not installed on each of the listed servers even though I know it is installed.

My code is:

cls
$HF = (read-host "Please enter hotfix ID?")

function Get-HotFix {
BEGIN {}
PROCESS {
$HF1 = $HF
$Name = (gwmi win32_operatingsystem -ComputerName $_).csname
$results = gwmi -Query "select * from win32_quickfixengineering"
if ($results -match $HF1) {Write-Host $HF1 "is installed on" $Name }
else {Write-Host $HF1 "not installed on" $Name }
}
END {}
}
gc (Read-Host "Enter Server List") | get-hotfix

 

Can anyone see what I am doing wrong?

Thanks

Lee

ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
02 Oct 2008 11:21 AM  
What do you enter when prompted for 'Read-Host "Enter Server List"' ?

Try this version:

function Get-HotFix($server,$hotFixID) {

PROCESS{
$results = gwmi win32_quickfixengineering -computer $_ -filter "HotFixID='$hotFixID'"

if ($results) {
$results | select CSName,HotFixID,@{n="Installed";e={"Yes"}}
} else {
$results = "" | select CSName,HotFixID,Installed
$results.CSName=$_
$results.HotFixID=$hotFixID
$results.Installed="No"
$results
}
}
}

cat servers.txt | Get-HotFix -hotFixID KB933729 | ft -auto


Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
02 Oct 2008 12:05 PM  
When prompted I enter the name and path to a server list (c:\servers.txt)
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
02 Oct 2008 12:30 PM  
Shay, I have modified the script to give the prompts that I require.

function Get-HotFix($server,$hotFixID) {

PROCESS{
$results = gwmi win32_quickfixengineering -computer $_ -filter "HotFixID='$hotFixID'"

if ($results) {
$results | select CSName,HotFixID,@{n="Installed";e={"Yes"}}
} else {
$results = "" | select CSName,HotFixID,Installed
$results.CSName=$_
$results.HotFixID=$hotFixID
$results.Installed="No"
$results
}
}
}

gc (Read-Host "serverlist") | Get-HotFix -hotFixID (Read-Host "Hotfix ID") | ft -auto



Thanks for your help. I don't know how you do it man, I spent 4 hours on this last night.

Cheers.

Lee
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
02 Oct 2008 12:36 PM  
One further question. If I wanted to colourise the results that returned no, where would I do that? I have attemped to add in a -foreground Red in certain places within the script but I screw it up. AGAIN!
ShayUser is Offline
Basic Member
Basic Member
Posts:271
Avatar

--
02 Oct 2008 08:23 PM  
See if this helps:
http://scriptolog.blogspot.com/2007/09/colorize-matching-output-in-pipeline.html
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
03 Oct 2008 05:53 PM  
Thanks Shay. I had a look earlier and ...you guessed it.. I could get it working. I'll play more over the weekend and see if I can figure out where I am going wrong.

Thanks

Lee
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer