header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Checking Hotfixes on Servers
Last Post 03 Oct 2008 09:53 AM by SynJunkie. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
Basic Member
Basic Member
Posts:126
Avatar

--
02 Oct 2008 02: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

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Oct 2008 03: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://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    02 Oct 2008 04:05 AM
    When prompted I enter the name and path to a server list (c:\servers.txt)
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    02 Oct 2008 04:30 AM
    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
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    02 Oct 2008 04:36 AM
    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!
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Oct 2008 12:23 PM

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    SynJunkieUser is Offline
    Basic Member
    Basic Member
    Posts:126
    Avatar

    --
    03 Oct 2008 09:53 AM
    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.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer