LDAP Bind Time (Task and Diagnostic)

Microsoft.Server.AD.2012.LDAPBind.ResponseCheck (ProbeActionModuleType)

Task to perform a LDAP bind.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script ProbeAction System.Secure.CommandExecuterProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds
MonitorBindTypeint$Config/MonitorBindType$Type of LDAP Bind to perform: 1) Non-SSL, 2) SSL, 3) Both.

Source Code:

<ProbeActionModuleType ID="Microsoft.Server.AD.2012.LDAPBind.ResponseCheck" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MonitorBindType" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="MonitorBindType" Selector="$Config/MonitorBindType$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="Script" TypeID="System!System.Secure.CommandExecuterProbe">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/LDAP_Bind_Time_Task.vbs$ $Config/MonitorBindType$ </CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>LDAP_Bind_Time_Task.vbs</Name>
<Contents><Script>'*************************************************************************
' Script Name - LDAP Bind Time
'
' Purpose - Binds to the local domain controller and outputs the time taken for the operation.
'
' (c) Copyright 2014, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

SetLocale("en-us")

const PerformanceDataType = 2
const StateDataType = 3

Sub Main()

Dim oSysInfo, oParams, sDomain, sError, sOutput
Dim iBindType, dtStart, oRoot, iTime

Set oParams = WScript.Arguments

if oParams.Count &lt;&gt; 1 then
wscript.echo "The number of command line arguments is incorrect: " &amp; vbCrLf &amp; _
"Expected: 1" &amp; vbCrLf &amp; _
"Actual: " &amp; oParams.Count

Exit Sub
End if

iBindType = CInt(oParams(0))

set oSysInfo = CreateObject("ADSystemInfo")
sDomain = oSysInfo.DomainDNSName

On Error Resume Next

' Bind using non-SSL
If iBindType = 3 or iBindType = 1 Then
dtStart = Now
set oRoot = GetObject("LDAP://" &amp; sDomain &amp; "/rootDSE")

If (Err.Number &lt;&gt; 0) Then
wscript.echo "Unable to bind to Root DSE." &amp; GetErrorString(Err)
Exit Sub
Else
iTime = DateDiff("s", dtStart, Now)

sOutput = "LDAP Bind Time: " &amp; iTime &amp; " second(s)" &amp; vbCrLf
End If
End If

' Bind using SSL
If iBindType = 3 or iBindType = 2 Then
dtStart = Now
set oRoot = GetObject("LDAP://" &amp; sDomain &amp; ":636/rootDSE")

If (Err.Number &lt;&gt; 0) Then
sOutput = sOutput &amp; "Unable to bind to Root DSE over SSL. The error was: " &amp; GetErrorString(Err)
Else
iTime = DateDiff("s", dtStart, Now)

sOutput = sOutput &amp; "LDAP Bind Time: " &amp; iTime &amp; " second(s)" &amp; vbCrLf
End If
End If

wscript.echo sOutput

End Sub

'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(oErr)
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
End If
End If

GetErrorString = vbCrLf &amp; vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

Call Main()
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</ProbeActionModuleType>