ISA 2006 – Создание бэкапа конфигурации средствами VBS

Не так давно возникла задача – создавать по расписанию бэкапы конфигурации ISA на тестовом массиве.

Естественно все виртуальное и на нем моделируются различные варианты окружений.
Традиционно при свободном полете мысли документировать то что сделал не особо хочется, и поэтому приходится либо клацать мышкой в GUI, либо запоминать то что делал.

Решение нашлось традиционным методом – раскапывание документации.

Рецепт таков.
Код представленный ниже, помещается в файл с произвольным именем.vbs и вызывается с параметром import или export

Sub ImportExport()

On Error Resume Next
Err.Clear

‘ Define a constant to indicate that no optional data will
‘ be exported or imported.
const noOptionalData = 0

‘Declare the objects needed
Dim root ‘ The FPCLib.FPC root object
Dim firewall ‘ An FPCArray object
Dim strComputer

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

‘ Create the root obect.
Set root = CreateObject("FPC.Root")

‘ Get a reference to the array object (firewall).
Set firewall = root.GetContainingArray
If WScript.Arguments(0) = "export" Then
‘ Export the configuration to the XML file.
‘ Notice that values are not specified for the optional parameters.
firewall.ExportToFile "D:\Backup\"& replace(Date,"/","_")+"_" & strComputername & "_Backup.xml", noOptionalData
If err.number <> 0 Then
message = "Backup (" & strComputername & ") Failed." & vbCrLf & "Error number: " & err.number & ". Error Description: " & err.description
else
message = "Backup (" & strComputername & ") configuration complete."
End If

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "ISA Backup job"
objMessage.From = "isa.admin@domain.com"
objMessage.To = "ISAArrayAuditors@domain.com"
objMessage.TextBody = message

‘==This section provides the configuration information for the remote SMTP server.
‘==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.10.100"
‘Server port (typically 25)
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

‘==End remote SMTP server configuration section==
objMessage.Send
WScript.Quit
End If

If WScript.Arguments(0) = "import" Then
Do
strfileloc = (InputBox(" Location and Filename to Import", "File to Import"))
If strfileloc <> "" Then
strInput = True
End if
Loop until strInput = True
WScript.Echo "Importing the configuration from " & strfileloc & " to the " & firewall.Name & " array object, a message will appear when complete"
‘ Import the firewall’s configuration from the XML file specified.
‘ Notice that values are not specified for some of the optional parameters.
firewall.ImportFromFile strfileloc,noOptionalData,,,True
WScript.Echo "Importing was completed successfully."
End If
End Sub


importExport


Информация об авторе

Сергей Мариничев.
Вы можете присоединиться ко мне в Facebook или в Twitter.

Если Вам понравилась статья, то вы можете подписаться на RSS.
А также бесплатно подписаться по E-mail и получать актуальную информацию в числе первых.

Получать обновления на email

Вы можете оставить комментарий.

Добавить комментарий

XHTML: Вы можете использовать тэги: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>