Microsoft Windows Server DNS NSLookup DS

Microsoft.Windows.Server.DNS.NSLookup.DS (DataSourceModuleType)

Script Data Source that uses NSLookup

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.PropertyBagProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
ScriptTimeoutSecondsint$Config/ScriptTimeoutSeconds$Script Timeout Seconds
QueryTimeoutSecondsint$Config/QueryTimeoutSeconds$Query Timeout Seconds
QueryTypestring$Config/QueryType$Query Type
HostNamestring$Config/HostName$Host Name
Serverstring$Config/Server$Server
AcceptNonAuthoritativebool$Config/AcceptNonAuthoritative$Accept Non Authoritative

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.DNS.NSLookup.DS" Accessibility="Public" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ScriptTimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="QueryTimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="QueryType" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="HostName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Server" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="AcceptNonAuthoritative" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="ScriptTimeoutSeconds" Selector="$Config/ScriptTimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="QueryTimeoutSeconds" Selector="$Config/QueryTimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="QueryType" Selector="$Config/QueryType$" ParameterType="string"/>
<OverrideableParameter ID="HostName" Selector="$Config/HostName$" ParameterType="string"/>
<OverrideableParameter ID="Server" Selector="$Config/Server$" ParameterType="string"/>
<OverrideableParameter ID="AcceptNonAuthoritative" Selector="$Config/AcceptNonAuthoritative$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.PropertyBagProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.Windows.Server.DNS.NSLookup.DS.vbs</ScriptName>
<Arguments>$Config/QueryType$ $Config/HostName$ $Config/Server$ $Config/AcceptNonAuthoritative$ $Config/QueryTimeoutSeconds$</Arguments>
<ScriptBody><Script>'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' ScriptName: Microsoft.Windows.Server.DNS.NSLookup.DS
'
' Purpose: DNS Server DNS NSLookup DataSource
'
' File: Microsoft.Windows.Server.DNS.NSLookup.DS.vbs
'*************************************************************************

Option Explicit

SetLocale("en-us")

Dim wmiNamespaceString, wmiQueryString, strCommand, strResult, ErrorMessage, ErrorNumber, strStdErr, strIgnoredErr, strStdOut
Dim strQueryType, strHostName, strServerName, strAcceptNonAuth, intQueryTimeout, strTempLine, NAString
Dim boolAcceptNonAuth, boolQTypeValid, boolIgnoreNAValid, boolIsNonAuth
Dim oArgs, objShell, objWshScriptExec, objStdOut, objStdErr

wmiNamespaceString = "winmgmts://./root/MicrosoftDNS"
wmiQueryString = "SELECT EventLogLevel FROM MicrosoftDNS_Server"
strCommand = ""
strResult = "Internal-Script-Error"
ErrorMessage = "No Errors"
ErrorNumber = 0
strStdErr = ""
strIgnoredErr = ""
strStdOut = ""

Dim arrNAStrings(5)
REM French
arrNAStrings(0) = "R&#xE9;ponse ne faisant pas autorit&#xE9; :"
REM German
arrNAStrings(1) = "Nicht autorisierende Antwort:"
REM Spanish
arrNAStrings(2) = "Respuesta no autoritativa:"
REM Italian
arrNAStrings(3) = "Risposta da un server non autorevole:"
REM English
arrNAStrings(4) = "Non-authoritative answer:"
REM Portuguese
arrNAStrings(5) = "Nao &#xE9; resposta de autoriza&#xE7;ao:"

Set objShell = CreateObject("WScript.Shell")

Set oArgs = WScript.Arguments
If (oArgs.Count &lt;&gt; 5) Then
ErrorMessage = "Expected 5 arguments. Received " &amp; CStr(oArgs.Count)
ErrorNumber = 1
Call ReturnPropertyBag
End If

strQueryType = UCase(oArgs(0))
strHostName = oArgs(1)
strServerName = oArgs(2)
strAcceptNonAuth = UCase(oArgs(3))
intQueryTimeout = CInt(oArgs(4))

Select Case strQueryType
Case "A"
boolQTypeValid = True
Case "CNAME"
boolQTypeValid = True
Case "PTR"
boolQTypeValid = True
Case "NS"
boolQTypeValid = True
Case "SOA"
boolQTypeValid = True
Case Else
boolQTypeValid = False
End Select

If Not boolQTypeValid Then
ErrorMessage = "Query Type must be A, CNAME, NS, PTR, or SOA"
ErrorNumber = 2
Call ReturnPropertyBag
End If

Select Case strAcceptNonAuth
Case "TRUE"
boolIgnoreNAValid = True
Case "FALSE"
boolIgnoreNAValid = True
Case Else
boolIgnoreNAValid = False
End Select

If Not boolIgnoreNAValid Then
ErrorMessage = "AcceptNonAuthoritative must be TRUE or FALSE"
ErrorNumber = 3
Call ReturnPropertyBag
End If

boolAcceptNonAuth = CBool(strAcceptNonAuth)

If (strHostName = "") Or (strServerName = "") Then
ErrorMessage = "HostName and ServerName may not be blank"
ErrorNumber = 4
Call ReturnPropertyBag
End If

strCommand = "cmd /c chcp 437 &amp;&amp; NSLookup.exe -timeout=" &amp; CStr(intQueryTimeout) &amp; " -querytype=" &amp; strQueryType &amp; " " &amp; strHostName &amp; " " &amp; strServerName

ON ERROR RESUME NEXT

Set objWshScriptExec = objShell.Exec(strCommand)

If Err.Number &lt;&gt; 0 Then
ErrorNumber = Err.Number
ErrorMessage = Err.Description
Call ReturnPropertyBag
End If

ON ERROR GOTO 0

Set objStdOut = objWshScriptExec.StdOut
While Not objStdOut.AtEndOfStream
strTempLine = objStdOut.ReadLine
strTempLine = Replace(strTempLine, vbCr, "")
strTempLine = Replace(strTempLine, vbLf, "")
strStdOut = strStdOut &amp; strTempLine
Wend

Set objStdErr = objWshScriptExec.StdErr
While Not objStdErr.AtEndOfStream
strTempLine = objStdErr.ReadLine
strTempLine = Replace(strTempLine, vbCr, "")
strTempLine = Replace(strTempLine, vbLf, "")
strTempLine = Replace(strTempLine, Chr(130), Chr(233))
strTempLine = Replace(strTempLine, Chr(135), Chr(231))

boolIsNonAuth = CBool("False")
For Each NAString In arrNAStrings
If strTempLine = NAString Then
boolIsNonAuth = CBool("True")
End If
Next

If boolAcceptNonAuth And boolIsNonAuth Then
strIgnoredErr = strIgnoredErr &amp; strTempLine
ElseIf strTempLine = "*** Can't find server name for address " &amp; strServerName &amp; ": Non-existent domain" Then
strIgnoredErr = strIgnoredErr &amp; strTempLine
Else
strStdErr = strStdErr &amp; strTempLine
End If
Wend

If strStdErr = "" Then
strResult = "Success"
Else
strResult = "Query-Failure"
End If

If (strQueryType = "CNAME") And Not ( Instr(1, strStdOut, "canonical name =", 1) &gt;= 1 ) Then
strResult = "Query-Failure"
End If

Call ReturnPropertyBag

Sub ReturnPropertyBag
Dim oAPI, oBag, HexErrorNumber
HexErrorNumber = "0x" &amp; Hex(ErrorNumber)

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

Call oBag.AddValue("Result", strResult)
Call oBag.AddValue("CommandLine", strCommand)
Call oBag.AddValue("StdOut", strStdOut)
Call oBag.AddValue("StdErr", strStdErr)
Call oBag.AddValue("IgnoredErrs", strIgnoredErr)
Call oBag.AddValue("ErrorMessage", ErrorMessage)
Call oBag.AddValue("ErrorNumber", HexErrorNumber)

Call oAPI.Return(oBag)

WScript.Quit

End Sub</Script></ScriptBody>
<TimeoutSeconds>$Config/ScriptTimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>