Создание бэкапа конфигурации 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

Закладки:
  • Print
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • RSS

Вы можете отслеживать комментарии к этой записи с помощью RSS 2.0. Вы можете оставить комментарий, или использовать trackback с вашего сайта.

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

Для отправки комментария вы должны авторизоваться.