DOWNLOAD THE CODE:
Download the Code 26969.zip

The search appears as a call to SearchAD, which specifies that the script wants to search the entire domain for PCs, starting at the root and going through all subtrees, and apply the filter as the search progresses. For any computer objects that aren't part of the Centrally Managed PCs AD group, the script retrieves the dNSHostName and the ADsPath and places both components into the arrPCs array for later manipulation. SearchAD also assigns a value of True or False to indicate whether the search was successful.

After a successful search, arrPCs contains a multidimensional array of attributes that match the search criteria. These attributes are the dNSHostName (i.e., the Fully Qualified Domain Name—FQDN—of the computer object, such as client12345.finance.mycorp.com) and ADsPath (i.e., the full LDAP path to the object in AD). The script loops through the array and attempts to run the CUSClientFileInstaller function on each client that the array elements represent. To perform this loop, the script uses the intIndex variable to loop from 0 to the last element in the array. If the search returned 12 results, arrPCs(5,0) and arrPCs(5,1) indicate the dNSHostName and ADsPath, respectively, of the fifth item in the array—assuming arrPCs(x,y) and assuming that x=0..11 and y=0..1. Because the script uses intIndex, it must ensure that it uses arrPCs(intIndex,0) and arrPCs(intIndex,1) within the loop to reference the correct array elements for that cycle through the loop. To make this process even easier, you can use strPC each time to represent arrPCs(intIndex,0).

For each client the script identifies as a member of the managed group, the script uses a function called IsHostReachable in GenericLibrary.vbs to ensure that the installation server can ping the client. This function returns True or False and uses the Ping command to test whether the installation server can contact the client.

When the installation server can reach the client, the script uses strPC, the client's DNS IP name, to call the CUSClientFilesInstaller function. If the function returns a result of 0, the installation was successful and the script uses the IADsGroup::Add method with the computer object's full LDAP path to add the client to the Centrally Managed PCs AD group.

Keeping Count of Successes and Failures
Because any number of things can go wrong with the corporate update system, tracking errors and reporting problems are important. To that end, the script in Listing 1 maintains a detailed log file and emails the administrator when the script finishes. In addition, to ensure that an administrator can obtain a quick view of a particular script run, the script writes a brief summary of the events of that particular script run for the log file and email alert.

If SimpleCUSClientTargetter.wsf installs the client files on a client, the script increments the intSuccess counter by 1. After a successful file installation, the script either increments intGrpAddSuccess if the script successfully added the client to the Centrally Managed PCs AD group or increments intGrpAddFail if the script failed to add the client to this group. The script also uses intFailedInstallScript to indicate that the script failed to install the necessary files on a client and intFailedUnreachable to indicate that the script was unable to even reach the host. All these variables create quick summary statistic lines that the script places into the strSummary variable. The script then adds these lines to the log file and to the body of the email message the script sends to the administrator. The SendMailToAdmins message-sending subprocedure in GenericLibrary.vbs adds support for attachments to the SendSimpleMailToAdmins subprocedure I described in Part 2. If the third parameter in the SendMailToAdmins subprocedure is blank, the script doesn't add a file attachment to the email message; otherwise, the script passes the file path to the subprocedure to attach the file to the email message. SendMailToAdmins doesn't include any error checking, but you can easily modify the subprocedure to ensure that the third parameter is a valid file path and that the file can be attached.

Looking Ahead
In the final article of this series, I'll concentrate on tips and tricks I've learned over the years while using the corporate update system. With the final piece of the puzzle, you'll be able to see how you can extend and enhance this system for your own use.

RELATED ARTICLES IN PREVIOUS ISSUES
You can obtain the following articles from the Windows Scripting Solutions Web site at http://www.winscriptingsolutions.com.

ALISTAIR G. LOWE-NORRIS
"Scripting a Corporate Update System, Part 2," November 2002, InstantDoc ID 26632

"Scripting a Corporate Update System," October 2002, InstantDoc ID 26360

"Scripting Solutions with WSH and COM: Advanced Methods for Task Scheduling,"
May 2002, InstantDoc ID 24592

"Rem: Using the Ping Command in WSH Code," March 2002, InstantDoc ID 23931

"Scripting Solutions with WSH and COM: Scheduling Automated Tasks,"
March 2002, InstantDoc ID 23935

"Automating Excel to Create Trend Charts," March 2000, InstantDoc ID 8186

"An ADSI Primer, Part 5: Using ADO to Script Fast ADSI Searches,"
May 1999, InstantDoc ID 5281

"An ADSI Primer, Part 2: Manipulating Active Directory Objects," February 1999, InstantDoc ID 4818

End of Article

Prev. page     1 2 [3]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

 
 

ADS BY GOOGLE