Archive for August, 2012|Monthly archive page

Update: Backup TMG with Powershell

In Uncategorized on August 7, 2012 at 20:18

If you like my content please do check out my new blog at ! 


Some time ago I posted a script to backup the TMG configuration using Powershell. Meindert Honig tested my script and gave me some feedback – if you did a backup from the TMG console the resulting XML file was bigger then when using my script. When I compared the xml files I discovered that when you use my script the server specific information isn’t exported. This due to the fact that I used the value “0” for the iOptionalData field in the ExportToFile method.

So if you did a backup you would have all the array stuff but not the server configuration ( including cache drives, installed web filters etc etc).  Lurking around I found an example to properly fill the IOptionalData field in this blogpost .

I’ll repost the entire augemted script ( I must admit the export file is now even bigger and I’ve been a bit lazy to figure out why – could it be caused by a different way of storing the data or is there some data in the FPC.Root.Array object that isn’t exported by the TMG console – maybe someone else can help me with that). This version does a backup of all the data ( confidential, group data) and encrypts it with a password.


# See the post I mentioned above for the MSDN page

$iOptionalData= 0x00000001 -bor 0x00000002 -bor 0x00000004 -bor 0x00000008

$Comment = “Your comment goes here”

$Password =”Very Secret Password”
if ($err)
    write-eventlog -logname Application -source TMGBackup -eventid 9999 -entrytype Warning -message “Backup
failed, cause: $err” -category 0
write-eventlog -logname Application -source TMGBackup -eventid 9000 -entrytype Information -message “Backup Succeeded” -category 0

You should of course first register the eventlog source using new-eventlog to register the TMGBackup eventlog source.