“区域已签名”属性数据源

Microsoft.Windows.DNSServer.2016.IsZoneSignedProperty.DS (DataSourceModuleType)

此数据源发现所有 Windows Server 2016 和 1709+ 区域中的“区域已签名”属性。

Knowledge Base article:

摘要

此数据源使用 Powershell commandlet 发现所有 Windows Server 2016 和 1709+ 区域中的“区域已签名”属性

配置

间隔(秒):应对值进行检查的频率(秒)。

同步时间:模块执行的同步时间。

超时(秒):等待模块完成执行的时间(秒)。

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Discovery.Scheduler Default
PS ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default
InstanceFilter ConditionDetection System.ExpressionFilter Default
Mapping ConditionDetection System.Discovery.FilteredClassSnapshotDataMapper Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$间隔(秒)对值进行采样的频率(秒)。
SyncTimestring$Config/SyncTime$同步时间模块执行的同步时间。
TimeoutSecondsint$Config/TimeoutSeconds$超时(秒)等待模块完成执行的时间(秒)。

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.DNSServer.2016.IsZoneSignedProperty.DS" Accessibility="Public">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>System!System.Discovery.MapperSchema</SchemaType>
<SchemaType>System!System.ExpressionEvaluatorSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ZoneName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerName" type="xsd:string"/>
<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="SyncTime" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PS" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>DNSZoneIsSignedProbe</ScriptName>
<ScriptBody><Script>

param ([String] $PrincipalName)

$SCRIPT_NAME = "DNSZoneIsSignedProbe"
$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."

$ErrorInfo = 5704
$EventWarn = 5702
$EventError = 5702
$EventSuccess = 5700


function FuncCheckService{
param($ServiceName)
try
{
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne "running")
{
return $false
}
return $true
}
catch
{
return $false
}
}

Function Set-Error($momAPI,[String]$ErrorMessage,$EventLevel,$EventType,[String]$ScriptName)
{
if ($null -eq $momAPI)
{
return
}

try
{
if ($null -ne $momAPI)
{
$momAPI.LogScriptEvent($ScriptName,$EventLevel,$EventType,$ErrorMessage)
}
}
catch
{
}

}

Function Import-CmdLets ($momAPI,[string]$ScriptName)
{
try
{
$dnsmodule = Get-Module -Name "DnsServer"
if ($null -eq $dnsmodule)
{
Import-Module DnsServer
}
}
catch [System.IO.FileNotFoundException]
{
$ErrorMessage = "Dns cmdlets doesn't exist."
Set-Error -momAPI $momAPI -ScriptName $ScriptName -EventLevel $EventError -EventType $EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage
exit
}
catch
{
$ErrorMessage = Get-ErrorMessage -Exception $_.Exception -ScriptName $ScriptName
Set-Error -momAPI $momAPI -ScriptName $ScriptName -EventLevel $EventError -EventType $EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage
exit
}
}

Function Get-ErrorMessage($Exception,[string]$ScriptName)
{
$ErrorMes = $Exception.Message
$ErrorMessage = @"
Module: $ScriptName

Error(s) was(were) occurred:
Error(s):
$ErrorMes

"@

return $ErrorMessage
}

Function Process-DiscoveryFailure
{
$ErrorMessage = Get-ErrorMessage -Exception $_.Exception -ScriptName $Script:SCRIPT_NAME
Set-Error -momApi $Script:momApi -ScriptName $Script:SCRIPT_NAME -EventLevel $Script:EventError -EventType $Script:EVENT_TYPE_ERROR -ErrorMessage $ErrorMessage

$discoveryData = $Script:momApi.CreateDiscoveryData(0, $Script:ElementID, $Script:TargetID)
$discoveryData.IsSnapshot = $false
$discoveryData
}

Import-Cmdlets -momAPI $momAPI -ScriptName $SCRIPT_NAME

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 Zone Is Signed Property Bag Powershell Script"

$DNSZones = Get-DnsServerZone -ComputerName $PrincipalName

if($DNSZones -ne $null)
{
if($DNSZones.Count -eq $null)
{
$ZoneCount = 1
}
else
{
$ZoneCount = $DNSZones.Count
}

for ($itmZone=0; $itmZone -lt $ZoneCount; $itmZone++)
{
if($ZoneCount -eq 1)
{
$ZoneObj = $DNSZones
}
else
{
$ZoneObj = $DNSZones.Item($itmZone)
}

if ($ZoneObj.IsAutoCreated -eq $false)
{
$PropertyBag = $momAPI.CreatePropertyBag()
$PropertyBag.AddValue("ZoneName", $ZoneObj.ZoneName)
$PropertyBag.AddValue("IsSigned", $ZoneObj.IsSigned)

$PropertyBag

Write-Host "$SCRIPT_NAME - Property Bag Added"
}
}

}

Write-Host "$SCRIPT_NAME - multiple property bag returned"

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="InstanceFilter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='ZoneName']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/ZoneName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="Mapping" TypeID="System!System.Discovery.FilteredClassSnapshotDataMapper">
<Expression/>
<ClassId>$MPElement[Name='Microsoft.Windows.DNSServer.2016.Zone']$</ClassId>
<InstanceSettings>
<Settings>
<Setting>
<Name>$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$</Name>
<Value>$Config/ComputerName$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.Windows.DNSServer.2016.Server']/Name$</Name>
<Value>$Config/ComputerName$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.Windows.DNSServer.2016.Zone']/ZoneName$</Name>
<Value>$Config/ZoneName$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.Windows.DNSServer.2016.Zone']/HostName$</Name>
<Value>$Config/ComputerName$</Value>
</Setting>
<Setting>
<Name>$MPElement[Name='Microsoft.Windows.DNSServer.2016.Zone']/IsSigned$</Name>
<Value>$Data/Property[@Name='IsSigned']$</Value>
</Setting>
</Settings>
</InstanceSettings>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Mapping">
<Node ID="InstanceFilter">
<Node ID="PS">
<Node ID="DS"/>
</Node>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>