The Add method creates a new FPCComputerSet object in the collection and returns a reference to it.
HRESULT Add( [in] BSTR Name, [out] IFPCComputerSet** ppNewItem );
Address of an interface pointer that on return points to the new IFPCComputerSet interface created.
This method can return one of the following:
Function Add( _ ByVal Name As String _ ) As FPCComputerSet
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.
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
Client | Requires Windows Vista or Windows XP. |
---|---|
Server | Requires Windows Server 2008. |
Version | Requires Forefront Threat Management Gateway (TMG). |
IDL |
Declared in Msfpccom.idl. |
DLL |
Requires Msfpccom.dll. |
Send comments about this topic to Microsoft
Build date: 11/30/2009
© 2008 Microsoft Corporation. All rights reserved.