IFPCComputerSets::Add method

Applies to: desktop apps only

The Add method creates a new FPCComputerSet object in the collection and returns a reference to it.

Syntax

HRESULT Add(
  [in]   BSTR Name,
  [out]  IFPCComputerSet **ppNewItem
);
FPCComputerSets.Add( _
  ByVal Name As String, _
  ByRef ppNewItem As IFPCComputerSet _
) As FPCComputerSet

Parameters

  • Name [in]

    C++ Required. BSTR that specifies the name of the new computer set.
    VB Required. String that specifies the name of the new computer set.
  • ppNewItem [out]
    Address of an interface pointer that on return points to the new IFPCComputerSet interface created.

Return value

C++

This method can return one of the following:

  • S_OK, indicating that the operation succeeded.
  • An error code, indicating that the operation failed. In this case, the [out] parameter returned is a null object.

VB

This method returns a reference to an FPCComputerSet object if successful. Otherwise, an error is raised that can be intercepted by using an error handler.

Examples

This VBScript script creates a new computer set with the user-specified name if it does not exist and imports all the names and IP addresses of the computers listed in a text file to the list of computers in the user-specified computer set.

Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_NotIpAddress = &HC0040302
Const ForReading = 1
' Define the delimiter used in the text file.
Dim delimiter         ' A String
delimiter = vbTab     
Main(WScript.Arguments)
Sub Main(args)
    If(args.Count <> 2) Then
        Usage
    End If
    AddComputersToComputerSet args(0), args(1)
End Sub
Sub AddComputersToComputerSet(fileName, computerSetName)
    ' 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
    ' 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(computerSetName)
    If Err.Number = Error_FileNotFound Then
        Err.Clear
        WScript.Echo "The " & computerSetName & " computer set does not exist. " _
            & "Creating it ..."
        Set computerSet = computerSets.Add(computerSetName)
    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")
    Set fileStream = fso.OpenTextFile(fileName, ForReading)
    On Error Resume Next
    Do While fileStream.AtEndOfStream <> True
        textRead = fileStream.ReadLine
        If textRead <> "" Then
            Err.Clear
            textArray = Split(textRead, delimiter)
            If UBound(textArray) <> 1 Then
                WScript.Echo "An improperly formed line was found in the text file."
                WScript.Echo "No changes will be saved."
                WScript.Quit
            End If
            computers.Item textArray(0)
            If Err.Number = Error_FileNotFound Then
                Err.Clear
                computers.Add textArray(0), textArray(1)
                If Err.Number = Error_NotIpAddress Then
                    WScript.Echo textArray (1) & " is not a valid IP address."
                Else
                    WScript.Echo "Adding " &  textArray(0) & " " _ 
                        & textArray(1) & " ..."
                End If
            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

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 (64-bit only)

Version

Forefront Threat Management Gateway (TMG) 2010

IDL

Msfpccom.idl

DLL

Msfpccom.dll

See also

FPCComputerSets

 

 

Build date: 7/12/2010