Windows Sever 2016 DNS Trust Points Discovery
Microsoft.Windows.DNSServer.2016.TrustPoint.Discovery (Discovery)
This workflow discovers all DNS Trust points all Windows Server 2016
Knowledge Base article:
Element properties:
Object Discovery Details:
Member Modules:
Source Code:
<Discovery ID="Microsoft.Windows.DNSServer.2016.TrustPoint.Discovery" Enabled="false" Target="Microsoft.Windows.DNSServer.2016.Server" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.DNSServer.2016.TrustPoint">
<Property TypeID="Microsoft.Windows.DNSServer.2016.TrustPoint" PropertyID="TrustPointName"/>
<Property TypeID="Microsoft.Windows.DNSServer.2016.TrustPoint" PropertyID="HostName"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" RunAs="Microsoft.Windows.DNSServer.2016.ActionAccount" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>15000</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverDNSTrustPoint</ScriptName>
<ScriptBody><Script>
param ([String] $ElementID, [String] $TargetID, [String] $ServerName)
$SCRIPT_NAME = "DiscoverDNSTrustPoint"
$ErrorActionPreference = "Stop"
# Event type constants
$EVENT_TYPE_LOG = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4
# Typed property bag constants
$PROPERTY_TYPE_ALERT = 0
$PROPERTY_TYPE_EVENT = 1
$PROPERTY_TYPE_PERFORMANCE = 2
$PROPERTY_TYPE_STATE = 3
# State type constants
$STATE_SUCCESS = "Success"
$STATE_WARNING = "Warning"
$STATE_ERROR = "Error"
$momAPI = new-object -comObject MOM.ScriptAPI
$DNS_NOT_RUNNING_EVENT_ID = 7654
$DNS_NOT_RUNNING_SCRIPT_MESSAGE = "DNS Server Service is not running. Exiting."
function FuncCheckService{
param($ServiceName)
try
{
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "running")
{
return $false
}
return $true
}
catch
{
return $false
}
}
$TrustPointType = "$MPElement[Name='Microsoft.Windows.DNSServer.2016.TrustPoint']$"
$CompNameProp = "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$"
$DNSNameProp = "$MPElement[Name='Microsoft.Windows.DNSServer.2016.Server']/Name$"
$EntityDNProp = "$MPElement[Name='System!System.Entity']/DisplayName$"
$TPNameProp = "$MPElement[Name='Microsoft.Windows.DNSServer.2016.TrustPoint']/TrustPointName$"
$HostNameProp = "$MPElement[Name='Microsoft.Windows.DNSServer.2016.TrustPoint']/HostName$"
if (-Not (FuncCheckService "DNS"))
{
$momAPI.LogScriptEvent($SCRIPT_NAME, $DNS_NOT_RUNNING_EVENT_ID, $EVENT_TYPE_ERROR, $DNS_NOT_RUNNING_SCRIPT_MESSAGE)
return
}
Write-Host "$SCRIPT_NAME - Executing DNS Trusted Points Discovery Powershell Script"
$discoveryData = $momAPI.CreateDiscoveryData(0, $ElementID, $TargetID)
$discoveryData.IsSnapshot = $true
$DNSTrustPoints = Get-DnsServerTrustPoint -ComputerName $ServerName
if($DNSTrustPoints -ne $null)
{
if($DNSTrustPoints.Count -eq $null)
{
$TPCount = 1
}
else
{
$TPCount = $DNSTrustPoints.Count
}
for ($itmTP=0; $itmTP -lt $TPCount; $itmTP++)
{
if($TPCount -eq 1)
{
$TPObj = $DNSTrustPoints
}
else
{
$TPObj = $DNSTrustPoints.Item($itmTP)
}
$TPState = $TPObj.TrustPointState
$TrustedPoint = $discoveryData.CreateClassInstance($TrustPointType)
$TrustedPoint.AddProperty($CompNameProp, $ServerName)
$TrustedPoint.AddProperty($DNSNameProp, $ServerName)
$TrustedPoint.AddProperty($TPNameProp, $TPObj.TrustPointName)
$TrustedPoint.AddProperty($HostNameProp, $ServerName)
$TrustedPoint.AddProperty($EntityDNProp, $TPObj.TrustPointName + " on " + $ServerName)
$discoveryData.AddInstance($TrustedPoint)
Write-Host "$SCRIPT_NAME - DNS Trusted Point Added to Discovery data"
}
}
$discoveryData
Write-Host "$SCRIPT_NAME - Discovery data returned"</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>ElementID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>TargetID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>ServerName</Name>
<Value>$Target/Host/Property[Type='Windows!Microsoft.Windows.Computer']/PrincipalName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>