|
Find Computers on which a HotFix is NOT installed
Download the ScriptAhead File: CheckForMissingHotFix.saf
The Problem:
You need a script to check the computers in your network and tell you if a specific HotFix is NOT installed in any of them.
The Solution:
Step 1: In order to make this script generic you want to define the HotFix ID as well as the computers to check from the command line each time you run the script. In this script you need two Named Command Line arguments:
FixID: that will contain the ID of the HotFix that you want to check
CNFile: the path to a text file that will contain the names of the computers that you want to check (one name per line)
Therefore you will be able to run the script by specifying different arguments each time, e.g.
cscript CheckForMissingHotFix.wsf /FixID:KB911562 /CNFile:c:\ComputerNames.txt
In ScriptAhead it is very easy to define the command line arguments that you want your script to accept. To do so you must select Tools|Define Command Line Arguments from the main menu. The following dialog will popup:

Click on the Add Button to define the first named argument:
Click Ok and press the Add button again to define the second argument:
Now the two arguments are defined and the values passed by the user will be accessible in the script through the variables $HotFixID and $CompNamesFile. The first dialog will now display the defined arguments:

Step 2: To start with you must read the names of the computers that you want to check and store them in a collection variable. To do so you will use the "Read Text File Contents" task

In the "File Path" box you enter the variable $CompNamesFile that contains the appropriate argument entered by the user. You may change the name of the collection variable that this task will generate to $ComputerNames:
Step 3: Use the "Display Message" task to display the header of the output:
Step 4: Use the "Loop through Collection" task to iterate though the computer names that are stored in the collection variable $ComputerNames
Step 5: Within the loop you will check for the existence of the specific HotFix in each computer. To do so you will use the "Get HotFix" task:

In the Properties dialog in the "Computer(s)" box you enter the variable $CurrentComputer. This is the variable defined in the Loop task that holds the name of the computer for the current iteration.

In the Filters tab you must specify that you want only the HotFix with the ID provided by the user (through the command line argument). Remember that the value passed by the user is stored in the variable $HotFixID
Step 6: Now we have the variable $HotFixes that will contain a collection of the HotFixes retrieved. It is obvious that if the collection contains 1 item then the HotFix is found (installed) in the computer of the current loop. On the other hand, if the collection is empty (contains 0 items) then the current computer does not have the HotFix installed. So you need to know the length of the collection stored in $HotFixes. To get the length you will use the "Count Collection" task

In the properties dialog you enter the $Hotfixes variable. The result (a number) will be stored in the variable $CollectionLentgh

Step 7: If the $CollectionLength is 0 then the HotFix is not installed on the current computer. So, all you have to do is use the "If" task you check the $CollectionLength variable and if 0 display the name of the current computer (using the "Display Message" task)

Finally the completed script is:

You may either run the script from within ScriptAhead or just generate it in a wsf file and use it independently.
|