Microsoft Windows Server DNS Zone Discovery (0 to 10 Percent)

Microsoft.Windows.Server.DNS.Zone.0to10PercentDiscovery (Discovery)

Discovers 0 to 10 Percent zones on the local DNS server

Knowledge Base article:

Summary

Uses WMI to discover 0 to 10 Percent DNS zones.

Element properties:

TargetMicrosoft.Windows.Server.DNS.Server
EnabledTrue
Frequency14640
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
  • Microsoft.Windows.Server.DNS.Zone
    • ZoneName
    • ZoneType
    • IsReverseZone
    • IsADIntegrated
    • AllowDynamicUpdates
    • AllowZoneTransfers
    • PrimaryServerName
    • ZoneFileName
    • UseWINS
    • HostName
    • NameServers
    • MasterServers
    • DisplayName
  • Microsoft.Windows.Server.DNS.Zone.Global
    • IsActivated
    • ZoneName
    • ZoneType
    • IsReverseZone
    • IsADIntegrated
    • AllowDynamicUpdates
    • AllowZoneTransfers
    • PrimaryServerName
    • ZoneFileName
    • UseWINS
    • HostName
    • NameServers
    • MasterServers
    • DisplayName
    • QueryOrder

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Microsoft.Windows.Server.DNS.ActionAccount

Source Code:

<Discovery ID="Microsoft.Windows.Server.DNS.Zone.0to10PercentDiscovery" Enabled="true" Target="Microsoft.Windows.Server.DNS.Server" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.Server.DNS.Zone">
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneType"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="IsReverseZone"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="IsADIntegrated"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="AllowDynamicUpdates"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="AllowZoneTransfers"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="PrimaryServerName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneFileName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="UseWINS"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="HostName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="NameServers"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="MasterServers"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.Server.DNS.Zone.Global">
<Property TypeID="Microsoft.Windows.Server.DNS.Zone.Global" PropertyID="IsActivated"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneType"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="IsReverseZone"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="IsADIntegrated"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="AllowDynamicUpdates"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="AllowZoneTransfers"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="PrimaryServerName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="ZoneFileName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="UseWINS"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="HostName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="NameServers"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone" PropertyID="MasterServers"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Microsoft.Windows.Server.DNS.Zone.Global" PropertyID="QueryOrder"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" RunAs="Microsoft.Windows.Server.DNS.ActionAccount" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>14640</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.Windows.Server.DNS.Zone.Discovery.vbs</ScriptName>
<Arguments>0 10</Arguments>
<ScriptBody><Script>'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' ScriptName: Microsoft.Windows.Server.DNS.Zone.Discovery
'
' Purpose: DNS Server Zone Discovery
'
' File: Microsoft.Windows.Server.DNS.Zone.Discovery.vbs
'*************************************************************************

Option Explicit

SetLocale("en-us")

Dim strSourceId, strManagedEntityId, strTargetComputer, strZoneName, wmiNamespaceString, wmiQueryString, junkVar
Dim strQueryOrder, zoneTypeString, dynamicType, strDataFile, colSOA, objSOA, colZones2
Dim ix, strMS, strSOA, nameServers
Dim boolIsActivated
Dim oAPI, oDiscoveryData, objWMIService, colitems, objItem, lInst, oReg, regVal, objItemIndex, initial, zoneCount, initialPercent, finalPercent, oArgs

strSourceId = "$MPElement$"
strManagedEntityId = "$Target/Id$"
strTargetComputer = "$Target/Host/Property[Type='Windows!Microsoft.Windows.Computer']/PrincipalName$"
wmiNamespaceString = "winmgmts://./root/MicrosoftDNS"
wmiQueryString = "SELECT * FROM MicrosoftDNS_Zone WHERE ZoneType &lt;&gt; 4"
Set oArgs = WScript.Arguments
If (oArgs.Count = 2) Then
initialPercent= CInt(oArgs(0))
finalPercent= CInt(oArgs(1))
End If
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, strSourceId, strManagedEntityId)

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

ON ERROR RESUME NEXT

set objWMIService = GetObject(wmiNamespaceString)

If Err.Number &lt;&gt; 0 Then
Call ReturnDiscovery
End If

set colitems = objWMIService.ExecQuery(wmiQueryString)
zoneCount=colitems.count
If Err.Number &lt;&gt; 0 Then
Call ReturnDiscovery
End If

If ( zoneCount = 0 ) Then
Call ReturnDiscovery
End If

ON ERROR GOTO 0


If((CInt(zoneCount) &lt; 10) AND (CInt(initialPercent) = 0)) Then
initial= 1
Else
If(CInt(zoneCount) &gt;= 10) Then
initial = CInt((initialPercent/100*zoneCount)+1)
zoneCount = CInt((finalPercent/100*zoneCount))
Else
initial=0
zoneCount=-1
End If
End If

For objItemIndex=(CInt(initial)) To (CInt(zoneCount))
Set objItem=colitems.ItemIndex(objItemIndex-1)

If Not IsNull(objItem.Name) Then

If Trim(LCase(objItem.Name)) = "globalnames" Then

If (oReg.GetDWordValue(&amp;H80000002, "SYSTEM\CurrentControlSet\Services\DNS\Parameters", "EnableGlobalNamesSupport", regVal) &lt;&gt; 0) Then
boolIsActivated = CBool("False")
Else
If CInt(regVal) = 1 Then
boolIsActivated = CBool("True")
Else
boolIsActivated = CBool("False")
End If
End If

If (oReg.GetDWordValue(&amp;H80000002, "SYSTEM\CurrentControlSet\Services\DNS\Parameters", "GlobalNamesQueryOrder", regVal) &lt;&gt; 0) Then
strQueryOrder = "Local Zone First"
Else
If CInt(regVal) = 1 Then
strQueryOrder = "Local Zone First"
Else
strQueryOrder = "Global Zone First"
End If
End If

Set lInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone.Global']$")
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone.Global']/IsActivated$", boolIsActivated)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone.Global']/QueryOrder$", strQueryOrder)


Else

Set lInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']$")

End If

select case cint(objItem.ZoneType)
case 1
zoneTypeString="Primary"
case 2
zoneTypeString="Secondary"
case 3
zoneTypeString="Stub"
case Else
zoneTypeString="Unknown"
end select

select case cint(objItem.AllowUpdate)
case 0
dynamicType="None"
case 1
dynamicType="Secure and NonSecure"
case 2
dynamicType="Secure Only"
case Else
dynamicType="Other"
end select

strDataFile = "null"
If not IsNull(objItem.DataFile) Then
strDataFile = objItem.DataFile
End If

If Not IsNull(objItem.MasterServers) Then
strMS=""
For ix = 0 To UBound(objItem.MasterServers)
strMS=strMS &amp; objItem.MasterServers(ix) &amp; " "
Next
End If

Set colSOA = objWMIService.ExecQuery("Select * from MicrosoftDNS_SOAType Where ContainerName = '" &amp; objItem.Name &amp; "'")
For Each objSOA In colSOA
If Right(objSOA.PrimaryServer,1) = "." Then
strSOA = Left(objSOA.PrimaryServer,Len(objSOA.PrimaryServer)-1)
Else
strSOA = objSOA.PrimaryServer
End If
exit for
Next

nameServers=""
Set colZones2 = objWMIService.ExecQuery("Select nshost from MicrosoftDNS_nstype Where ContainerName = '" &amp; objItem.containername &amp; "'" &amp; " and domainname='" &amp; objItem.Name &amp; "'" &amp; " and dnsservername='" &amp; objItem.dnsservername &amp; "'" )
nameServers = GetNameServers(colZones2)

call lInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", strTargetComputer)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Server']/Name$", strTargetComputer)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/ZoneName$", objItem.Name)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/ZoneType$", zoneTypeString)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/IsReverseZone$", CBool(objItem.Reverse))
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/IsADIntegrated$", CBool(objItem.DSIntegrated))
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/AllowDynamicUpdates$", dynamicType)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/AllowZoneTransfers$", CInt(objItem.SecureSecondaries))
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/PrimaryServerName$", strSOA)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/ZoneFileName$", strDataFile)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/UseWINS$", CBool(objItem.UseWins))
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/HostName$", strTargetComputer)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/NameServers$", nameServers)
call lInst.AddProperty("$MPElement[Name='Microsoft.Windows.Server.DNS.Zone']/MasterServers$", strMS)
call lInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", objItem.Name &amp; " on " &amp; strTargetComputer)
Call oDiscoveryData.AddInstance(lInst)

End If

Next

Call ReturnDiscovery



Sub ReturnDiscovery

Call oAPI.Return(oDiscoveryData)
WScript.Quit

End Sub



Function GetNameServers(ZonesColl)
Dim DataList, objTmpZone

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "nshost", 200, 255
DataList.Open

For Each objTmpZone In ZonesColl
DataList.AddNew
DataList("nshost") = objTmpZone.nshost
DataList.Update
Next

DataList.Sort = "nshost"
If DataList.EOF Then
GetNameServers = ""
Exit Function
End If
DataList.MoveFirst
Do Until DataList.EOF
nameServers=nameServers &amp; DataList.Fields.Item("nshost") &amp; " "
DataList.MoveNext
Loop

DataList.Close
Set DataList = Nothing

GetNameServers = nameServers
End Function</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>