<WriteActionModuleType ID="AD_Replication_Monitoring_Helper1.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_Helper1.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 < 1 then
Wscript.Quit -1
End if
Dim oAPI
Set oAPI = CreateObject("Mom.ScriptAPI")
Err.Clear
Dim sStateValuePath
sStateValuePath= "HKLM\" & oAPI.GetScriptStateKeyPath(oParams(0))
' Registry Path to share data across scripts
Dim REG_Key
REG_Key = sStateValuePath & "\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 & "\" & 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 & "\" & strKey , strData )
Err.Clear
End Sub
'******************************************************************************
Dim dtPerfData
Dim dtLocal
dtPerfData = GetData ("ReplicationLatencyPerfDataFlag")
If IsDate(dtPerfData) Then
dtPerfData = CDate(dtPerfData)
Dim localTime
Err.Clear
localTime = FromUTC(dtPerfData)
if 0 <> Err Then
ScriptError "convert to local time from UTC." & vbCrLf & _
"Replication Latency performance data will not be collected on " & _
"this machine during this execution of the script." & GetLastError(Err)
Else
If 60 < DateDiff("n", localTime, Now) Then
dtLocal = ToUTC(Now)
Call SetData("ReplicationLatencyPerfDataFlag", dtLocal)
End If
End If
Else
dtLocal = ToUTC(Now)
Call SetData("ReplicationLatencyPerfDataFlag", dtLocal)
End If