The AddComputer.vbs script creates a computer rule element in the ISA Server Network Object Toolbox. When creating a computer rule element, some values are required: a name of the object and an IP address. The description is optional, but it can be a good idea to type in a comment describing the role of the computer.
Tip | For more information on the Windows Script SDK, you can download the Windows Script 5.6 Documentation from http://www.microsoft.com/downloads/details.aspx?FamilyID=&DisplayLang=en. |
'==================================================================== ' ' PURPOSE: Add a Computer Element to ISA Server 2004 ' ' NAME: AddComputer.vbs ' ' RUN: cscript AddComputer.vbs <ComputerName> <IP Address> [Description] ' ' WHERE: Run on an ISA Server 2004, Local on Server ' ' COMMENT: This script was written by Jesper Hanno Hansen. ' ' VERSION: 1.0 '==================================================================== ' Create an arguments Object to get the parameters from the input Dim objArguments Set objArguments = WScript.Arguments ' Count the input parameters, if less than 2, show help If objArguments.Count < 2 Then ShowHelp Else ' There were more than 2 parameters, set the first to the ' Computername and the second to the IPAddress. Dim strComputer strComputer = WScript.Arguments(0) Dim strIPAddress strIPAddress = WScript.Arguments(1) ' Set the remaining input as the description Dim strDescription For i = 2 To objArguments.Count -1 strDescription = strDescription & " " & objArguments(i) Next ' Trim the description to remove the last space strDescription = Trim(strDescription) End If ' Show information on the Computer element that will be created WScript.Echo "Creating a new Computer element with the following information" WScript.Echo "" WScript.Echo "Computer Name: " & strComputer WScript.Echo "IP Address: " & strIPAddress WScript.Echo "Description: " & strDescription ' Calling the Sub to create a new computer element DoCreateComputer strComputer, strIPAddress, strDescription Sub DoCreateComputer(ComputerName,ComputerIPAddress,ComputerDescription) ' Enabling Error handling On Error Resume Next ' Create an objRoot Object to ISA Server 2004 Dim objRoot Set objRoot = CreateObject("FPC.Root") CheckError ' Create an FPCArray Object to retrieve the current ISA Array Dim objFPCArray Set objFPCArray = objRoot.GetContainingArray CheckError ' Create an FPCRuleElements Object to get access to FPCComputers Dim objFPCRuleElements Set objFPCRuleElements = objFPCArray.RuleElements CheckError ' Create an FPCComputers Object to get access to FPCComputer Dim objFPCComputers Set objFPCComputers = objFPCRuleElements.Computers CheckError ' Trying to retrieve the computer from the Computer elements. ' If retrieval of the computer succeeds, the computer element ' already exists and the script should not do anything with it. Dim objComputerExists Set objComputerExists = objFPCComputers.Item(ComputerName) ' If the error code is 0 = Success, then there is a computer with the ' same name. If Err.Number = 0 Then WScript.Echo "The Computer Element " & ComputerName & _ " exist, stopping here" WScript.Quit Else Err.Clear End If ' Using the Add method from the FPCComputer object ' The Add method requires 2 input parameters ' Name and IPAddress as strings Dim objFPCComputer Set objFPCComputer = objFPCComputers.Add(ComputerName, ComputerIPAddress) CheckError ' Check if the ComputerDescription is empty, if not we should add ' the description to the computer element. If ComputerDescription <> "" Then objFPCComputer.Description = ComputerDescription CheckError End If ' Show information that the script is going to save the new computer ' element, and checking for any error. WScript.Echo "Saving Computer element" objFPCComputers.Save CheckError WScript.Echo "Computer element successfully saved" End Sub ' Used to check if the script is in an error state, if true quit Sub CheckError If Err.Number <> 0 Then WScript.Echo "" WScript.Echo "Error Number : " & "0x" & Hex(Err.Number) WScript.Echo "Error Description : " & Err.Description WScript.Quit End If End Sub ' Used to show help on the screen, if input parameters is less ' than 2 Sub ShowHelp WScript.Echo "Please use cscript AddComputer.vbs <ComputerName>" & _ " <IP Address> [Description]" WScript.Echo "For Example:" WScript.Echo "" WScript.Echo "Cscript AddComputer.vbs Server01.domain.local" & _ " 192.168.1.2 FTP Server" WScript.Echo "" WScript.Echo "Where Computername and IP Address is required" WScript.Echo "and Description is optional." WScript.Quit End Sub