Share via


Improving on the Offline GAL Sync solution

Managing FIM Sync Export Files

So I had a chance to work on a few additional enhancements to the LDIF-Based Offline GALSync solution.

In the area of FIM file management one of the needs was to maintain an archive of each LDIF Export file which is created. So I decided it would be best to do the following:

1. Run the LDIF Export routine via WMI script (as usual)

2. Copy the resulting file to a folder C:\Archive

3. Run a PowerShell script to copy the file and embed the timestamp in the filename. So we copy it from “LDIF_Export.ldif” to include the timestamp “LDIF_Export_MMDDYY_HHMMSS.ldif”.

A Powershell routine which will do this (and I had to sweat it out as I don’t spend a great many hours each week writing PowerShell!) looks like this…

#filename: CopyFileWithTimestamp.ps1

param( [string] $input_filename)

function get_new_filename
{
#
# this is a comment
# note, we assume the file exists...otherwise this will bomb out
#
param( [string] $infile)
$file1 = get-item $infile
$file2 = $file1.name.replace($file1.extension,"")
$destfile = $file1.directoryname + "\" + $file2 + "~" + $file1.lastwritetime.tostring("MMddyyyy_HHmmss") + $file1.extension
return $destfile
} # end function

#
$dest_filename = get_new_filename( $input_filename )
$file1 = get-item $input_filename
$file1.copyto($dest_filename)
write-host "file copied"

Putting it all together

Now the execution control for the LDIF Export process can be managed from a single .CMD file, which will be invoked via the Windows Scheduler, such as:

cscript LDIF_Export.vbs
Set LDIFFILE=My_LDIF_Export.ldif
copy "..\madata\LDIF_MA\%LDIFFILE%" c:\archive
powershell set-executionpolicy Unrestricted
powershell -command ".\CopyFileWithTimestamp.ps1 'c:\archive\%LDIFFILE%' "

 
This little PowerShell script should come in handy for other purposes in the future. Also it gave my scripting skill set a nice little workout.

Reporting on Run History

Another area for improvement is to create some notification between the two organizations around the ongoing synchronization process. It will be pretty easy to get all the FIM Run History data programmatically (via WMI) and perhaps send the results via email to the system administrators on both sides.  FIM features, as inherited from ILM 2007 FP1, are pretty strong in the WMI Provider classes which give us more precise control over the operational aspects of a solution.

Metadirectoryservices namespace classes

The MIIS_RunHistory interface is documented here: https://msdn.microsoft.com/en-us/library/ms697834(v=VS.85).aspx. MIIS_RunHistory gives us a collection of each item in the Run History stored on the server. The MIIS_RunHistory class defines the RunDetails method, which is an XML collection defined as a run_history element.

If you do a Bing search on "MIIS_Runhistory samples" you'll find quite a number of helpful samples. These will be easy to incorporate into a more robust solution. 

 

Improving the File Transfer process

Another area of the solution I've been investigating is the Windows Azure table storage and the SQL Azure functionality. I'll expand on this portion of the solution in my next posting, after I finish thoroughly digesting a recent issue of MSDN Magazine which has some articles about Data In the Cloud.

Until then, its Happy Holidays and Merry Christmas to all. Hallelujah!