This script reads a text file (like the one created in the ExportServer.vbs script previously) line by line and adds a computer rule element in ISA Server 2004 for each computer.

 '======================================================================== ' PURPOSE: Add all the Computers from the text file ExportedServers.txt ' ' NAME: ImportServers.vbs ' ' RUN: cscript ImportServers.vbs <Path to ExportedServers.txt> ' ' WHERE: Run on an ISA Server 2004, Local on Server ' ' COMMENT: The script will add Computer elements for all Computers from the '          text file created with ExportServers.vbs '          This script was written by Jesper Hanno Hansen. ' ' VERSION: 1.0 '========================================================================= ' Enabling Error handling On Error Resume Next 'Set ForReading from OpenAsTextStream Method Const ForReading = 1 ' Create an arguments Object to get the parameters from the input Dim objArguments Set objArguments = WScript.Arguments ' Count the input parameters, if less than 1, show help If objArguments.Count <> 1 Then    ShowHelp Else    ' Set the parameter to the Input File name    Dim strFileName    strFileName = WScript.Arguments(0) End If ' Create a Root Object to ISA Server 2004 Dim objRoot Set objRoot = CreateObject("FPC.Root") ' Create an FPCArray Object to retrieve the current ISA Array Dim objFPCArray Set objFPCArray = objRoot.GetContainingArray '  Create an FPCRuleElements Object to get access to FPCComputers Dim objFPCRuleElements Set objFPCRuleElements = objFPCArray.RuleElements ' Create an FPCComputers Object to get access to FPCComputer Dim objFPCComputers Set objFPCComputers = objFPCRuleElements.Computers ' Calling the Sub to read the file ReadFromFile strFileName ' Show information that the script is going to save the new computer ' element, and checking for any error. WScript.Echo "Saving Computer element(s)" objFPCComputers.Save CheckError WScript.Echo "Computer element(s) successfully saved" Sub ReadFromFile(strFileName)    ' Create a FileSystem Object    Dim objFileSystemObject    Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")    ' Check if the file exists, if not show error information and quit    If Not objFileSystemObject.FileExists(strFileName) Then          WScript.Echo "Could not open the file " & strFileName          WScript.Quit    End If    ' Create a File Object, for reading the file    Dim objFile    Set objFile = objFileSystemObject.OpenTextFile(strFileName, ForReading)    ' Declare strLine    Dim strLine    ' Loop through the file context until the end    Do While objFile.AtEndOfStream <> True          ' Set strLine to the line          strLine = objFile.ReadLine          ' if the line contains | (The separator for Computername,          ' IPAddress and Description) go on          If InStr(strLine, "|") Then                ' Create an Array that contains the line for each |                arrData = Split(strLine,"|")                ' Declare the variables                Dim strDNSName, strIPAddress, strDescription                ' Set the Array data to the variables                strDNSName = arrdata(0)                strIPAddress = arrdata(1)                strDescription = arrdata(2)                ' Stop if the IP Address is empty, since this is                ' a required parameter for adding a computer element                ' to ISA Server                If strIPAddress = "" Then                      ' Show information that this computer could not be                      ' added                      WScript.Echo "Could not add the server " & _                      strDNSName & " because the IP Address is missing..."                Else                      ' Show information that we will try to add the                      ' computer                      WScript.Echo "Trying to add " & strDNSName & " " & _                      strIPAddress & " " & strDescription                      '  Calling the Sub to create a new computer element                      DoCreateComputer strDNSName, strIPAddress _                      , strDescription                End If          Else                      ' If the line does not contain a |, skip the line                      objFile.SkipLine          End If    Loop    ' Close the file    objFile.Close End Sub Sub DoCreateComputer(ComputerName,ComputerIPAddress,ComputerDescription)    ' Enabling Error handling    On Error Resume Next    ' Trying to retrieve the computer from the Computer elements    ' if it does, 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, skipping"          Exit Sub    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 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 1 Sub ShowHelp    WScript.Echo "Please use cscript ImportServers.vbs <Path to ExportedServers.txt>"    WScript.Echo "For Example:"    WScript.Echo ""    WScript.Echo "Cscript ImportServers.vbs C:\ExportedServers.txt"    WScript.Quit End Sub 

Microsoft Internet Security and Acceleration ISA Server 2004 Administrator's Pocket Consultant
Microsoft Internet Security and Acceleration (ISA) Server 2004 Administrators Pocket Consultant (Pro-Administrators Pocket Consultant)
ISBN: 0735621888
EAN: 2147483647
Year: 2006
Pages: 173

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: