
Script Listing: AddArraysFromList.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 connects to the Configuration Storage server specified by the
' user using the credentials of a specified ISA Server administrator with
' read/write permissions for accessing the array configuration. The script
' then creates new arrays with the names listed in a text file.
' Note that the text file must contain a list of array names with the name of
' each array on a separate line.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const ForReading = 1
Main(WScript.Arguments)
Sub Main(args)
If(args.Count <> 5) Then
Usage
End If
AddArrays args(0), args(1), args(2), args(3), args(4)
End Sub
Sub AddArrays(css, userName, domain, password, fileName)
' Create the root object.
Dim root ' The FPCLib.FPC root object
Set root = CreateObject("FPC.Root")
'Declare the other objects needed.
Dim isaArrays ' An FPCArrays collection
Dim fso ' A FileSystemObject object
Dim fileStream ' A TextStream object
Dim textRead ' A String
Dim i ' An Integer
' Connect to the Configuration Storage server.
On Error Resume Next
root.ConnectToConfigurationStorageServer css, userName, domain, password
CheckError
' Get a reference to the arrays collection.
Set isaArrays = root.Arrays
CheckError
On Error GoTo 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.OpenTextFile(fileName, ForReading)
Do While fileStream.AtEndOfStream <> True
textRead = fileStream.ReadLine
If textRead <> "" Then
On Error Resume Next
isaArrays.Item textRead
If Err.Number = Error_FileNotFound Then
WScript.Echo "Creating the " & textRead & " array..."
Err.Clear
isaArrays.Add textRead
CheckError
End If
End If
Loop
On Error GoTo 0
' Save the changes.
isaArrays.Save
WScript.Echo "Done!"
End Sub
Sub CheckError()
If Err.Number <> 0 Then
WScript.Echo "An error occurred: 0x" & Hex(Err.Number) & ". " _
& Err.Description
Err.Clear
WScript.Quit
End If
End Sub
Sub Usage()
WScript.Echo "Usage:" & VbCrLf _
& " Cscript " & WScript.ScriptName & " CSS UserName Domain Password " _
& "FileName" & VbCrLf _
& "" & VbCrLf _
& " CSS - Name of Configuration Storage server" & VbCrLf _
& " UserName - User name of an ISA Server administrator" & VbCrLf _
& " Domain - Domain of the user specified in UserName" & VbCrLf _
& " Password - Password of the user specified in UserName" & VbCrLf _
& " FileName - Text file containing the list of arrays"
WScript.Quit
End Sub