Microsoft KB Archive/311187

= How to Write a Script to Detect Problems with the Import File =

Article ID: 311187

Article Last Modified on 10/30/2006

-

APPLIES TO


 * Microsoft Metadirectory Services 2.1
 * Microsoft Metadirectory Services 2.2 Service Pack 1
 * Microsoft Metadirectory Services 2.2 Service Pack 1

-



This article was previously published under Q311187



SUMMARY
A large number of connector space objects or metaverse objects can be made obsolete if connectivity is lost between the Cdir program and the connected directory. If you are using the provisioning agent (Together Administration management agent [TAMA]) to provision one or more other connected directories, the objects may be deleted from those folders if connectivity is lost. This article describes how to write a script to prevent metaverse objects from being made obsolete if connectivity is lost.



MORE INFORMATION
When you run a management agent in Full mode, Microsoft Metadirectory Services (MMS) assumes that the import file contains all of the objects that are discovered in the connected directory. When the management agent is not in Delta mode, MMS assumes that any object that is not present in the import file has been deleted from the connected directory. MMS assumes that the object will also be made obsolete from the metadirectory. If connectivity was lost while the file was being built during the management agent run, the file may be truncated and metaverse objects may be made obsolete by mistake. To prevent this behavior, you can write an executable code which renames the previous import file and checks the new import file against the previous file for size discrepancies. If the file does not meet the check, your code can delete the file and MMS does not make metaverse objects obsolete. You can write this executable code in any language (such as VBScript or Perl), so that the executable code can be called by the management agent control script.

For example, you can write a code that renames the existing import file from the previous run at the start of the current run, and then checks the size of the new import file against the previous file. If the new file is significantly smaller than the previous file, MMS either deletes or renames the import file and synchronization is stopped. If no import file is present or if the file exists but is zero bytes in size, MMS stops the synchronization process. When this behavior occurs, the following data is logged in the Zscript.log file:

19012-ERROR: can not open [import]


 * Reference of Error Code******

ERROR 19012: DS_RC_FILE_ERROR

To write this code, you must write two VBS scripts and call them from the management agent control script. Use the scripts that are described in the following sections as a sample only. Although, these scripts have been tested in a lab environment, you may have to use additional logic to adapt these scripts to satisfy the specific requirements of your current environment. Additionally, you may want to use these scripts to enhance the capability of the existing scripts. For example, you may want to add additional error checking to test for the existence of the import files before you run either script.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

How to Write the SaveFile.vbs File
To write a VBScript code to save the old import file before the new import file is written:  Start a text editor such as Notepad.  Copy the following code to Notepad (make sure to change the value of the import file paths to match your environment): '*********************************************************** 'Save the old Import file 'In this example the MA working directory is number 6 '***********************************************************

Dim oFS, wshshell

Set oFS = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;) oFS.CopyFile &quot;C:\zoomserv\data\Ds\00000006\import&quot;,&quot;C:\zoomserv\data\Ds\00000006\import.old&quot;

Set wshshell = wscript.CreateObject(&quot;wscript.shell&quot;)

'Log event to application log wshshell.LogEvent 0, &quot;Renamed Import File&quot;

'Clean up Set oFS = Nothing Set wshshell = Nothing  Save the file as SaveFile.vbs.

How to Write the CheckSize.vbs File
To write a VBScript code to test the size of the new file in comparison to the old file, and then delete the new file if it is less than 95 percent of the size of the old file:  Start a text editor such as Notepad.  Copy the following code to Notepad (make sure to change the value of the import file paths to match your environment): '*********************************************************** 'Delete new Import file if size is < 95% of old Import file 'In this example, the MA working directory is number 6 '***********************************************************

'Declare variables Dim oFS, oFile1, oFile2, oldsize, newsize, wshshell Set oFS = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;) Set oFile1 = oFS.GetFile(&quot;C:\zoomserv\data\Ds\00000006\import&quot;) Set oFile2 = oFS.GetFile(&quot;C:\zoomserv\data\Ds\00000006\import.old&quot;) newsize = oFile1.Size oldsize = oFile2.Size

'Compare size to old file size If newsize < 0.95 * oldsize Then oFS.DeleteFile &quot;C:\zoomserv\data\Ds\00000006\import&quot; End If

Set wshshell = wscript.CreateObject(&quot;wscript.shell&quot;)

'Log event to application log wshshell.LogEvent 1, &quot;Import File Too Small, Deleted&quot;

'Clean up Set oFS = Nothing Set oFile1 = Nothing Set oFile2 = Nothing Set wshshell = Nothing  Save the file as CheckSize.vbs.</li></ol>

How to Make Changes to the MAScript.scr File to Incorporate the Other Scripts
 Start the MMS Compass utility, and then locate the management agent for which you want to run the .vbs files that you created in the earlier sections.</li> Click Design MA.</li> Click the Control MA Operations tab.</li> Click the MA Control Script tab.</li>  Locate the following line of code: IF %zcDsPerformDiscovery% = TRUE THEN IF %zcRequestFlash% = TRUE THEN Flash Start of Users Discovery ENDIF echo********************************************************** echo Start of Users Discovery echo ****************************************************************** </li>  Add the following code: Execute SaveFile.VBS </li>  Locate the following line of code: echo ****************************************************************** echo Synchronizing Metadirectory Users echo ****************************************************************** </li>  Add the follow line of code after the echo statements and before the Importt.exe program is run: Execute CheckSize.VBS </li></ol>
 * 1) Executing the Save script located in \zoomserv\bin directory.
 * 1) Executing the CheckSize script located in the \zoomserv\bin directory.

Additionally, Microsoft recommends that you set a deletion limit on the management agent to a specific threshold:
 * 1) Click the management agent.
 * 2) On the Action menu, click Operate MA.
 * 3) Click the Operational Settings tab.
 * 4) Click the Limits tab.
 * 5) In the Abort the synchronization process if _ consecutive deletions are encountered box, change the value to 100 (or use another reasonable numeric value).

Additional query words: mms metadirectory zoomit obsolete

Keywords: kbinfo kbenv KB311187

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.