Export (0) Print
Expand All

Managing the List of Computers in a Computer Set

Microsoft® Internet Security and Acceleration (ISA) Server uses various types of network entities to specify the sources and destinations in policy rules. These network entities include networks, network sets, address ranges, computers, computer sets, domain name sets, subnets, and URL sets.

This document focuses on computer sets. A computer set may include a list (collection) of IP address ranges, a list of subnets, and a list of computers. The definition of each computer in the list of computers associates a computer name with a single IP address. Computer sets can be referenced in the definitions of connection limit policies, network rules, access rules, server publishing rules, Web publishing rules, system policy rules, cache rules, and routing rules (Web chaining rules).

Although computer sets can be managed in ISA Server Management, if you need to configure a computer set that includes a long list of computers, you may find it more convenient to use scripts to create and maintain the list of computers using a text file. The text file can be generated programmatically from an existing computer set, edited in a text editor, and used to configure a new computer set or update an existing computer set.

A single computer set is defined by an FPCComputerSet ISA Server administration COM object, and all the computer sets defined in an ISA Server array are contained in the FPCComputerSets collection for the array. The FPCComputerSets collection for an array (an FPCArray object) is accessed through the ComputerSets property of the FPCRuleElements object for the array. In turn, the FPCRuleElements object is accessed through the RuleElements property of the FPCArray object that represents the array.

The lists of IP address ranges, subnets, and computers included in a computer set are represented by an FPCAddressRanges collection, an FPCSubnets collection, and an FPCComputers collection, respectively. Each FPCComputer object in the FPCComputers collection provides the following properties for defining a computer:

  • Name. This property gets or sets the name of the computer.
  • IpAddress. This property gets or sets the IP address associated with the computer.

The Microsoft Visual Basic® Scripting Edition (VBScript) code in ListComputersInComputerSet.vbs (listed later in this document) retrieves the collection of computers in the computer set specified by the user and displays the name and IP address of each computer included in the computer set. This script must be run on an ISA Server 2006 or ISA Server 2004 computer with the Microsoft Firewall service installed, but it can be modified to run on a remote management computer.

To use this script, paste the code in the script listing into a text editor, save it in a file named ListComputersInComputerSet.vbs, and run it from a command prompt.

Usage:

CScript ListComputersInComputerSet.vbs CsName

CsName specifies a computer set.

After you run the script without generating an error, you can use the redirection operator (>) to save the script output to a file. You can then edit this file in a text editor and use it to configure a new computer set or update the computer set used to create it.

Example:

CScript ListComputersInComputerSet.vbs "My Computer Set" > MyTextFile.txt

To list the computers included in a computer set
  1. Create an instance of the FPC COM object, which is known as the root object and provides access to the other ISA Server administration COM objects.

  2. Declare an FPCArray object, an FPCComputerSets collection, an FPCComputerSet object, an FPCComputers collection, and an FPCComputer object.

  3. Get references to the FPCArray object, the FPCComputerSets collection, and the FPCComputerSet object that represents the specified computer set.

  4. Get a reference to the FPCComputers collection that represents the collection of computers in the specified computer set.

  5. If at least one computer is defined in the specified computer set, use a For…Next loop to iterate through the collection of computers in the specified computer set and display the name retrieved from the Name property and the IP address retrieved from the IpAddress property for each computer defined in the collection.

Script listing: ListComputersInComputerSet.vbs

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Microsoft Corporation. All rights reserved.
' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE
' ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE
' REMAINS WITH THE USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR
' WITHOUT MODIFICATION, IS HEREBY PERMITTED.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This script retrieves the collection of computers in the computer set
' specified by the user and displays the name and IP address of each
' computer included in the computer set. 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

'Define the constants needed
Const Error_FileNotFound = &H80070002

Main(WScript.Arguments)

Sub Main(args)
    If(args.Count <> 1) Then
        Usage
    End If
    ListComputersInComputerSet args(0)
End Sub

Sub ListComputersInComputerSet(csName)

    ' Create the root object.
    Dim root  ' The FPCLib.FPC root object
    Set root = CreateObject("FPC.Root")

    ' Declare the other objects needed.
    Dim isaArray        ' An FPCArray object
    Dim computerSets    ' An FPCComputerSets collection
    Dim computerSet     ' An FPCComputerSet object
    Dim computers       ' An FPCComputers collection
    Dim computer        ' An FPCComputer object

    ' Get references to the array object 
    ' and the computer sets collection.
    Set isaArray = root.GetContainingArray()
    Set computerSets = isaArray.RuleElements.ComputerSets

    ' Retrieve the specified computer set.
    On Error Resume Next
    Set computerSet = computerSets.Item(csName)
    If Err.Number = Error_FileNotFound Then
        Err.Clear
        WScript.Echo "The " & csName & " computer set " _
            & "could not be found."
        WScript.Quit
    End If
    On Error GoTo 0

    ' Retrieve the collection of computers in the computer set.
    Set computers = computerSet.Computers

    'Display the name and IP address of each computer.
    If computers.Count > 0 Then
        For Each computer In computers
            WScript.Echo computer.Name & vbTab & computer.IpAddress
        Next
    Else
        WScript.Echo _
            "No computers are included in the computer set specified."
    End If
End Sub 

Sub Usage()
    WScript.Echo "Usage:" & VbCrLf _
        & "  CScript " & WScript.ScriptName & " CsName" _
        & VbCrLf _
        & "" & VbCrLf _
        & "  CsName  - Name of a computer set " 
    WScript.Quit
End Sub

The Microsoft Visual Basic Scripting Edition (VBScript) code in AddComputersToComputerSet.vbs (listed later in this document) creates a new computer set with the name specified by the user if it does not exist and imports all the names and IP addresses of computers listed in a text file to the list of computer names and IP addresses in the new computer set. If the specified computer set already exists, the existing computers are removed from it, and then the computer names and IP addresses in the text file are added. In either case, duplicates are not added. This script must be run on an ISA Server 2006 or ISA Server 2004 computer with the Microsoft Firewall service installed, but it can be modified to run on a remote management computer.

The text file must contain a list of computer names and IP addresses with the name and IP address of each computer separated by a tab character on a separate line.

To use this script, paste the code in the script listing into a text editor, save it in a file named AddComputersToComputerSet.vbs, and run it from a command prompt.

Usage:

CScript AddComputersToComputerSet.vbs FileName CsName

FileName specifies the text file containing a list of the computers to be added and their IP addresses.

CsName specifies the computer set to which the computers are to be added.

To add computers to a computer set from a file
  1. Create an instance of the FPC COM object, which is known as the root object and provides access to the other ISA Server administration COM objects.

  2. Declare an FPCArray object, an FPCComputerSets collection, an FPCComputerSet object, an FPCComputers collection, a FileSystemObject object, and a TextStream object.

  3. Get references to the FPCArray object, the FPCComputerSets collection, and the FPCComputerSet object that represents the specified computer set. If the specified computer set does not exist, create it.

  4. Get a reference to the FPCComputers collection that represents the collection of computers in the specified computer set.

  5. Create an instance of the FileSystemObject object, and call the OpenTextFile method on it to retrieve a TextStream object that represents the text file specified by the user.

  6. In a While loop, call the Remove method on the FPCComputers collection for each computer defined in the collection to clear the existing computers from the computer set.

  7. In a While loop, call the ReadLine method of the TextStream object to read each successive line in the text file, call Split to separate the text read in each line into two strings at the tab character, and call the Add method of the FPCComputers collection with the first string (the computer name) as the Name parameter of the method and the second string (the IP address) as the IPAddress parameter.

  8. Call the Save method of the FPCComputerSets collection to write the changes in the stored configuration.

Script listing: AddComputersToComputerSet.vbs

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Microsoft Corporation. All rights reserved.
' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE
' ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE
' REMAINS WITH THE USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR
' WITHOUT MODIFICATION, IS HEREBY PERMITTED.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This script creates a new computer set with the name specified by the 
' user if it does not exist and imports all the names and IP addresses 
' of computers listed in a text file to the list of computer names and 
' IP addresses in the new computer set. If the specified computer set 
' already exists, the existing computers are removed from it, and then
' the computer names and IP addresses in the text file are added. In
' either case, duplicates are not added.
' Note that the text file must contain a list of computer names and IP
' addresses with a name and IP address of each computer separated by 
' a tab character on a separate line.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_FileAlreadyExits = &H800700B7
Const Error_NotIpAddress = &HC0040302
Const ForReading = 1

Main(WScript.Arguments)

Sub Main(args)
    If(args.Count <> 2) Then
        Usage
    End If
    AddComputersToComputerSet args(0), args(1)
End Sub

Sub AddComputersToComputerSet(fileName, csName)

    ' Create the root object.
    Dim root  ' The FPCLib.FPC root object
    Set root = CreateObject("FPC.Root")

    'Declare the other objects needed.
    Dim isaArray        ' An FPCArray object
    Dim computerSets    ' An FPCComputerSets collection
    Dim computerSet     ' An FPCComputerSet object
    Dim computers       ' An FPCComputers collection
    Dim fso             ' A FileSystem object
    Dim fileStream      ' A TextStream object
    Dim textRead        ' A String
    Dim textArray       ' An Array
    Dim i               ' An Integer

    ' Get references to the array object 
    ' and the computer sets collection.
    Set isaArray = root.GetContainingArray()
    Set computerSets = isaArray.RuleElements.ComputerSets

    ' Retrieve the specified computer set.
    On Error Resume Next
    Set computerSet = computerSets.Item(csName)
    If Err.Number = Error_FileNotFound Then
        Err.Clear
        WScript.Echo "The " & csName & " computer set " _
            & "does not exist. Creating it ..."
        Set computerSet = computerSets.Add(csName)
    End If
    On Error GoTo 0

    ' Retrieve the collection of computers included
    ' in the computer set.
    Set computers = computerSet.Computers

    Set fso = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    Set fileStream = fso.OpenTextFile(fileName, ForReading)
    If Err.Number <> 0 Then
        WScript.Echo "The file specified could not be found."
        WScript.Quit
    End If
    On Error GoTo 0

    ' Clear the existing computers from the computer set and then
    ' add the computers from the file.
    i = computers.Count
    If i > 0 Then
        WScript.Echo "Removing the existing computers..." 
    End If
    Do While i > 0
        computers.Remove i
        i = i - 1
    Loop
    WScript.Echo "Adding computers from the file "  _ 
        & fileName & "..."

    On Error Resume Next
    Do While fileStream.AtEndOfStream <> True
        textRead = fileStream.ReadLine
        If textRead <> "" Then
            Err.Clear
            textArray = Split(textRead, vbTab)
            If UBound(textArray) <> 1 Then
            WScript.Echo "The line " & textRead & " in the " _
                    & "text file is improperly formed."
                WScript.Echo "No changes will be saved."
                WScript.Quit
            End If
            computers.Add textArray(0), textArray(1)
            If Err.Number = Error_FileAlreadyExits Then
                WScript.Echo "A duplicate line for the computer " _
                    & textArray(0) & " was ignored."
                Err.Clear
            ElseIf Err.Number = Error_NotIpAddress Then
                WScript.Echo _
                    textArray (1) & " is not a valid IP address."
                Err.Clear
            Else
                WScript.Echo "Adding " &  textArray(0) & " " _ 
                    & textArray(1) & " ..."
            End If
        End If
    Loop
    On Error GoTo 0

    ' Save the changes.
    computerSets.Save
    WScript.Echo "Done!"
End Sub 

Sub Usage()
    WScript.Echo "Usage:" & VbCrLf _
        & "  CScript " & WScript.ScriptName & " FileName CsName" _
        & VbCrLf _
        & "" & VbCrLf _
        & "  FileName - Text file containing the list of computers" _
        & VbCrLf _
        & "  CsName   - Computer set to which the computers " _
        & "will be added" 
    WScript.Quit
End Sub
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft