Exporting and Importing a Forefront TMG Configuration

This VBScript example exports the configuration of a Forefront TMG array to a specified .xml file or imports the configuration stored in a specified .xml file to an ISA Server array. The script includes a single subprocedure, called ImportExport.

This example is included as the ImportExport.vbs script in the Samples\Admin folder of the Forefront TMG Software Development Kit (SDK).

The following procedure lists the steps used to export the configuration of a Forefront TMG computer to an .xml file and to import the configuration in an .xml file to an ISA Server computer in the code example that follows.

To export and import a Forefront TMG configuration

  1. Declare an FPC object and an FPCArray object.
  2. Create an instance of the FPC COM object, which provides access to the other Forefront TMG administration COM objects.
  3. Get a reference to the existing FPCArray object.
  4. If exporting is requested, perform the following task:
    • Call the ExportToFile method without any optional data to export the array configuration to the .xml file specified in the command argument.
  5. If importing is requested, perform the following task:
    • Call the ImportFromFile method without any optional data and set the fResetRequiredServices parameter to True to import the configuration into Forefront TMG.

The following code can be saved to a .vbs file and run from a command prompt on a computer running Forefront TMG with the Microsoft Firewall service installed.

Sub ImportExport()
	' Define a constant to indicate that no optional 
	' data will be exported or imported.
	Const noOptionalData = 0
	If WScript.Arguments.Count <> 2 Then
		WScript.Echo "Error: Invalid number of parameters." & vbCrLf & _
					 "Syntax:" & vbCrLf & _
					 "ImportExport {e | i} filename"
		Exit Sub
	End If
	'Declare the objects needed
	Dim root	' The FPCLib.FPC root object
	Dim isaArray  ' An FPCArray object
	' Create the root object.
	Set root = CreateObject("FPC.Root")
	' Get a reference to the array object. 
	Set isaArray = root.GetContainingArray()
	If WScript.Arguments(0) = "e" Then
	 WScript.Echo "Exporting the configuration of the " & _
					 isaArray.Name & " array object to " & _
					 WScript.Arguments(1) & " ..."
	' Export the array configuration to the XML document.
	' Notice that values are not specified for the 
	' optional parameters.
	isaArray.ExportToFile WScript.Arguments(1),noOptionalData
	WScript.Echo "Exporting was completed successfully."
	WScript.Quit
	End If
	If WScript.Arguments(0) = "i" Then
	WScript.Echo "Importing the configuration from " & _
					WScript.Arguments(1) & " to the " & _
					isaArray.Name & " array object ..."
	' Import the array configuration from the XML 
	' file specified. Notice that values are not 
	' specified for some of the optional parameters.
	isaArray.ImportFromFile WScript.Arguments(1),noOptionalData,,,True
	WScript.Echo "Importing was completed successfully."
	End If
End Sub
ImportExport

In the call to the ImportFromFile method in this script, the default value of the CleanCollections parameter (False) is used. With this value, the information in the imported configuration file is added to the existing configuration. When you import a configuration exported from one Forefront TMG installation to the configuration of another installation, you must set the CleanCollections parameter in the call to the ImportFromFile method to True to overwrite any information in the existing configuration.

You can modify this script to overwrite any information in the existing configuration and to use it to import a configuration exported from one Forefront TMG installation to another installation by replacing the line containing the call to the ImportFromFile method with the following line:

	isaArray.ImportFromFile WScript.Arguments(1),noOptionalData,,True,True

Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.