AD Replication Collection Control script (Sources)

AD_Replication_Monitoring_Helper2.WriteAction (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.Windows.Server.AD.ActionAccountProfile
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<WriteActionModuleType ID="AD_Replication_Monitoring_Helper2.WriteAction" Accessibility="Internal" RunAs="AD!Microsoft.Windows.Server.AD.ActionAccountProfile" Batching="false">
<Configuration>
<xsd:element name="ManagementGroupName" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>AD_Replication_Monitoring_Helper2.vbs</ScriptName>
<Arguments>$Config/ManagementGroupName$</Arguments>
<ScriptBody><Script>
'*************************************************************************
' Script Name - AD Replication Monitoring helper
'
' Purpose - Enable AD replication monitoring.
'
' Assumptions - Script is run by a timed event
'
' (c) Copyright 2001, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

Dim oParams
Set oParams = WScript.Arguments
if oParams.Count &lt; 1 then
Wscript.Quit -1
End if


Dim oAPI
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear

Dim sStateValuePath
sStateValuePath= "HKLM\" &amp; oAPI.GetScriptStateKeyPath(oParams(0))


' Registry Path to share data across scripts
Dim REG_Key
REG_Key = sStateValuePath &amp; "\AD Management Pack\AD Replication Monitoring"

Dim oReg
oReg=null


'******************************************************************************
Function ToUTC(dtLocal)
'
' Purpose: To convert a date time to UTC
'
' Arguments: dtLocal
'
' Returns: Date, wrt to UTC
'
Dim oSet, oOS, lTZOffset
Set oSet = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")

For Each oOS In oSet
lTZOffset = oOS.CurrentTimeZone
Next

dtLocal = dtLocal - (lTZOffset / 1440) ' Minutes per day

ToUTC = dtLocal
End Function

'******************************************************************************
Function FromUTC(dtUTC)
'
' Purpose: To convert a date time from UTC to Local
'
' Arguments: dtUTC
'
' Returns: Date, wrt to local time
'
Dim oSet, oOS, lTZOffset
Set oSet = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")

For Each oOS In oSet
lTZOffset = oOS.CurrentTimeZone
Next

dtUTC = dtUTC + (lTZOffset / 1440) ' Minutes per day

FromUTC = dtUTC
End Function

'******************************************************************************
Function GetData(strKey)
'
' Purpose: Retrieves data out of a varset. Uses the key to determine what
' data to retrieve.
'
' Arguments: strKey, the key of the data to retrieve
'
' Returns: String, the data to return or an empty string
'
On Error Resume Next
If IsNull(oReg) Then
Set oReg = CreateObject("WScript.Shell")
End If
Dim regData
regData = oReg.RegRead(REG_Key &amp; "\" &amp; strKey )
If IsNull(regData) or IsEmpty(regData) or regData = "" Then
GetData = ""
Else
GetData = regData
End If
Err.Clear
End Function

'******************************************************************************
Sub SetData(strKey, strData)
'
' Purpose: To store data in a varset. If the key exists then the data
' associated with that key is replaced, otherwise the key/data
' combination is added to the varset.
'
' Arguments: strKey, the key of the line to replace
' strData, the data to associate with the key
'
' Returns: Nothing
If IsNull(oReg) Then
Set oReg = CreateObject("WScript.Shell")
End If
Call oReg.RegWrite(REG_Key &amp; "\" &amp; strKey , strData )
Err.Clear
End Sub
'******************************************************************************

Dim dtPerfData
Dim dtLocal
dtPerfData = GetData ("ReplicationCollectionPerfDataFlag")
If IsDate(dtPerfData) Then
dtPerfData = CDate(dtPerfData)
Dim localTime
Err.Clear
localTime = FromUTC(dtPerfData)
if 0 &lt;&gt; Err Then
ScriptError "convert to local time from UTC." &amp; vbCrLf &amp; _
"Replication Latency performance data will not be collected on " &amp; _
"this machine during this execution of the script." &amp; GetLastError(Err)
Else
If 60 &lt; DateDiff("n", localTime, Now) Then
dtLocal = ToUTC(Now)
Call SetData("ReplicationCollectionPerfDataFlag", dtLocal)
End If
End If
Else
dtLocal = ToUTC(Now)
Call SetData("ReplicationCollectionPerfDataFlag", dtLocal)
End If
'******************************************************************************

</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>