Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Add method creates a new FPCComputerSet object in the collection and returns a reference to it.
C++
Syntax
HRESULT Add(
[in] BSTR Name,
[out] IFPCComputerSet** ppNewItem
);
Parameters
Name
Required. BSTR that specifies the name of the new computer set.ppNewItem
Address of an interface pointer that on return points to the new IFPCComputerSet interface created.
Return Value
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.
Visual Basic
Syntax
Function Add( _
ByVal Name As String _
) As FPCComputerSet
Parameters
- Name
Required. String that specifies the name of the new computer set.
Return Value
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.
Example Code
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
| Client | Requires Windows 7 or Windows Vista. |
| Server | Requires Windows Server 2008 R2 or Windows Server 2008 x64 Edition with SP2. |
| Version | Requires Forefront Threat Management Gateway (TMG) 2010. |
| IDL | Declared in Msfpccom.idl. |
| DLL | Requires Msfpccom.dll. |
See Also
Send comments about this topic to Microsoft
Build date: 6/30/2010