How to Use the Zscript "-define" Parameter to Control Management Agents at Run-Time (297884)



The information in this article applies to:

  • Microsoft Metadirectory Services 2.1
  • Microsoft Metadirectory Services 2.2
  • Microsoft Metadirectory Services 2.2 SP1

This article was previously published under Q297884

SUMMARY

When you use the -define parameter in the Zscript command line, you can accommodate different run-time conditions by use of a single Microsoft Metadirectory Services Management Agent (MA). Generally, a parameter that is sent to the originating .cmd file sets one or more variables on the Zscript command line. These variables are then used in the Mascript.scr template to configure attribute values at run-time that are referenced by the Cdir_AD.dll file if the computer is running the Active Directory MA, or by IMPORTT (if the computer is running a standard MA).

MORE INFORMATION

Use the following sample batch file to set up different behaviours for the same Active Directory MA. If the batch file is called with the parameter Weekday, the MA runs in Delta mode. If the batch file is called with the parameter Weekend, the MA runs in Full mode. By using this technique, you can lock down run-time behavior to prevent any unintended configuration changes that are made with the Compass client from affecting the necessary outcome of the MA.

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.

Batch File Code

In a file named "My_Batch_File.bat", add the following code:
@ECHO OFF 
REM ========================== 
REM Script to run the Active Directory Management Agent 
REM 
REM Accepts one parameter 
REM usage: MMS-AD-Script.cmd Weekend | Weekday  
REM 
REM 	WEEKDAY - Runs the Management Agent in delta mode 
REM	WEEKEND - Runs the Management Agent in full mode 
REM ========================== 

 
REM ========================== 
IF /I '%1' == 'weekend' GOTO :WEEKEND  
IF /I '%1' == 'weekday' GOTO :WEEKDAY 
GOTO :EOF 
 
REM ========================== 
:WEEKDAY 
ECHO. 
ECHO Processing WEEKDAY script 
REM *** Run Management Agent in delta mode 
ECHO. 
ECHO Starting Management Agent 
ECHO %DATE% %TIME% 
@ZSCRIPT -DN "ma=Primary  MA,DsaName=mmsserver,ou=Servers,dc=microsoft,dc=com" -DEFINE "DELTA=TRUE" 
GOTO :EOF 
 
REM ========================== 
:WEEKEND 
ECHO. 
ECHO Processing WEEKEND script 
REM *** Run Management Agent in full mode 
ECHO. 
ECHO Starting Management Agent 
ECHO %DATE% %TIME% 
@ZSCRIPT -DN "ma=Primary  MA,DsaName=mmsserver,ou=Servers,dc=microsoft,dc=com" -DEFINE "DELTA=FALSE" 
GOTO :EOF
				

MAScript Code

The following Mascript.scr file would then behave according to the value of the defined variable "DELTA".
cd %zcDsDirectory% 
output -append adma.log 
echo Starting MAScript 
 
### This section is used by the scheduled command script. 
### It sets selected MA attributes and environment variables to ensure  
### changes configured using the Compass client do not override the  
### intended behaviour of the scheduled MA runs. 
IF %DELTA% = TRUE THEN 
      SET zcDsRole = "LINK" 
      SET zcDsPerformDiscovery = "TRUE" 
      SET zcDsPerformMetaSync = "TRUE" 
      SET zcMAProcessUsers = "TRUE" 
      SET zcDSImportDelta = "TRUE" 
      VSET DeltaScheduledUpdate = "TRUE" 
ENDIF 
IF %DELTA% = FALSE THEN 
      SET zcDsRole = "LINK" 
      SET zcDsPerformDiscovery = "TRUE" 
      SET zcDsPerformMetaSync = "TRUE" 
      SET zcMAProcessUsers = "TRUE" 
      SET zcDSImportDelta = "FALSE" 
      VSET FullScheduledUpdate = "TRUE" 
ENDIF 
### Main section of the control script 
 
if %DeltaScheduledUpdate% = TRUE 
then 
   echo 
************************************************************** 
   echo * Scheduled delta metadirectory and Active Directory update 
   echo  ************************************************************** 
   SET zcDsImportDelta = "TRUE"  
   SET zcOperateMA = 1 
endif 
if %FullScheduledUpdate% = TRUE 
then 
   echo  ************************************************************** 
   echo * Scheduled full metadirectory and Active Directory update 
   echo  ************************************************************** 
   SET zcDsImportDelta = "FALSE"  
   SET zcOperateMA = 1 
endif
				
To set up a working scenario:
  1. Edit the Path Environment Variable to include c:\zoomserv\bin. For more information about how to change environment variables in Windows 2000, refer to the Windows 2000 Help topic, "To add or change the values of environment variables."
  2. Name the batch file my_batch_file.bat and place it in the working directory of the Active Directory MA.
  3. Copy the sample code from the "MAScript Code" section in this article to the MAScript of the Active Directory MA:
    1. In the Compass utility, select the Active Directory MA that you are going to schedule.
    2. On the Action panel, click Design MA.
    3. On the MA Control Script tab, copy the MAScript code to the file. Comment out any existing text, and then add the above MA Script code in its place.
    4. Click OK to close the file, and to save your changes.
  4. To manually start the script, type the following command line at a command prompt:

    c:\zoomserv\data\ds\00000002\My_Batch_File.bat weekend

    Note: To start in Full mode, use the Weekend parameter, and to start in Delta mode, use the Weekday parameter. Or, to completely automate the process, schedule the batch file to run at certain intervals.

Modification Type:MinorLast Reviewed:1/18/2006
Keywords:kbenv kbhowto KB297884