' Listing 8: The ProcessServers Subroutine Private Sub ProcessServers(strInputFile, arrServerList, arrExServers, _ outFileName1, outFileName2, outFileName3, outFileName4) ' Declare the standard variables for the script template. Dim objFSO, strLComputer, objServer, strServerData, strComputer Dim strOU, h, strNLength, SpToAdd, strIPAddress, strPingStatus Dim strConnection, i, strOSVersion, strDomainRole, strNTBDomain Dim j, k, l, m, outFile1 outFile2, outFile3, outFile4 ' Declare the custom variables for the script's specific tasks. Dim strVariable_for_Specific_Task ' Define the constant for and instantiate the FileSystemObject object. Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") ' Get the local computer name for the WMIconnection function. strLComputer = CreateObject("WScript.Network").ComputerName For Each objServer In arrServerList strServerData = objServer ' ******* BEGIN CALLOUT A ******* If Len(strInputFile) > 0 Then strComputer = strServerData Else strComputer = Split(strServerData,vbTab)(1) strOU = Split(strServerData,vbTab)(2) End If ' ******* END CALLOUT A ******* If Not excludedServer(strComputer, arrExServers) Then ' Count each record for display. h = h + 1 strNLength = Len(h) Select Case strNLength Case 1 SpToAdd = 3 Case 2 SpToAdd = 2 Case 3 SpToAdd = 1 Case 4 SpToAdd = 0 End Select ' Print the process message. PrintMsg3 Space(SpToAdd) & h & Space(2) & "Processing server: " _ & strComputer & ". . ." ' Clear the variables. strIPAddress = "" : strPingStatus = "" : strConnection = "" PrintMsg4 "Pinging server " & strComputer & ". . ." ' ******* BEGIN CALLOUT B ******* ' Ping the server. strIPAddress = getPingIP(strComputer, strPingStatus) ' ******* END CALLOUT B ******* If strPingStatus = "On line" Then PrintMsg4 "Checking for connection status on " & strComputer & ". . ." ' ******* BEGIN CALLOUT C ******* ' Test the WMI connection. strConnection = WMIConnection(strComputer, strLComputer) ' ******* END CALLOUT C ******* If strConnection <> "" Then i = i + 1 If Len(strInputFile) > 0 Then If i = 1 Then ' Write the first line as a header. Set outFile1 = objFSO.OpenTextFile(outFileName1, _ ForWriting, True) outFile1.WriteLine "No." & vbTab & "Host Name" & vbTab _ & "IP Address" & vbTab & "Error Information" End If PrintMsg4 "***** Error connecting to " & strComputer & " ***** . . ." PrintMsg5 strConnection outFile1.WriteLine i & vbTab & strComputer & vbTab & _ strIPAddress & vbTab & strConnection Else If i = 1 Then ' Write the first line as a header. Set outFile1 = objFSO.OpenTextFile(outFileName1, _ ForWriting, True) outFile1.WriteLine "No." & vbTab & "Host Name" & vbTab & _ "IP Address" & vbTab & "OU Container" & vbTab & _ "Error Information" End If PrintMsg4 "***** Error connecting to " & strComputer & " ***** . . ." PrintMsg5 strConnection outFile1.WriteLine i & vbTab & strComputer & vbTab & _ strIPAddress & vbTab & strOU & vbTab & strConnection End If Else ' Clear the variables. strOSVersion = "" : strDomainRole = "" : strNTBDomain = "" ' ******* BEGIN CALLOUT D ******* ' Get the OS version and service pack. strOSVersion = getOSVersion(strComputer) ' Get the server role. strDomainRole = getDomainRole(strComputer) ' Get the NetBIOS domain name. strNTBDomain = getNetBIOSDomain(strComputer) ' Get the OU name if the server name is from an input file. If Len(strInputFile) > 0 Then strOU = getOU(strComputer, strNTBDomain) End If ' If any of the variable names is blank, set it to Unknown. If strDomainRole = "" Then strDomainRole = "Unknown" If strOSVersion = "" Then strOSVersion = "Unknown" If strNTBDomain = "" Then strNTBDomain = "Unknown" If strOU = "" Then strOU = "Unknown" ' ******* END CALLOUT D ******* ' ******* BEGIN CALLOUT E ******* ' Below is the area that contains the variables that accept the ' return values from the custom functions to perform queries, ' configuration changes, or other tasks. These variables are ' used for writing information to the log file. This area can also ' contain task-specific subroutines that don't return values. ' AREA FOR CODE THAT PERFORMS A TASK. ' Write your code's return value in the main log file. Here's an ' example of how the code might look: ' j = j + 1 ' If j = 1 Then ' Write the first line as a header. ' Set outFile2 = objFSO.OpenTextFile(outFileName2, _ ' ForWriting, True) ' outFile2.WriteLine "No." & vbTab & "Host Name" & vbTab & _ ' "IP Address" & vbTab & "OU Container" & vbTab & _ ' "Operating System" & vbTab & "Server Role" & vbTab & _ ' "Domain" & vbTab & "Header for specific task" ' End If ' Write the result to the log file. ' outFile2.WriteLine j & vbTab & strComputer & vbTab & _ ' strIPAddress & vbTab & strOU & vbTab & strOSVersion & _ ' vbTab & strDomainRole & vbTab & strNTBDomain & _ ' vbTab & strVariable_for_Specific_Task ' ******* END CALLOUT E ******* End If ElseIf strPingStatus = "Off line" Then ' Log the offline servers. PrintMsg4 strComputer & " is currently off line." l = l + 1 If l = 1 Then Set outFile3 = objFSO.OpenTextFile(outFileName3, ForWriting, True) outFile3.WriteLine "No." & vbTab & "Host Name" & _ vbTab & "IP Address" End If outFile3.WriteLine l & vbTab & strComputer & vbTab & strIPAddress Else ' Log the unknown host servers. PrintMsg4 strComputer & " is an unknown host." m = m + 1 If m = 1 Then Set outFile4 = objFSO.OpenTextFile(outFileName4, ForWriting, True) outFile4.WriteLine "No." & vbTab & "Host Name" End If outFile4.WriteLine m & vbTab & strComputer End If End If Next ' Close log files and clean up the variables. If IsObject(outFile1) Then outFile1.Close: Set outFile1 = Nothing ElseIf IsObject(outFile2) Then outFile2.Close: Set outFile2 = Nothing ElseIf IsObject(outFile3) Then outFile3.Close: Set outFile3 = Nothing ElseIf IsObject(outFile4) Then outFile4.Close: Set outFile4 = Nothing End If Set objFSO = Nothing End Sub