Microsoft Windows Server DNS WMI DS

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

Data Source that tests the DNS WMI provider

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
PS ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
SyncTimestring$Config/SyncTime$Sync Time

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.DNSServer.2016.WMI.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="SyncTime" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PS" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Microsoft.Windows.Server.DNS.WMI.DS.ps1</ScriptName>
<ScriptBody><Script>#Copyright (c) Microsoft Corporation. All rights reserved.

#*************************************************************************
# ScriptName: Microsoft.Windows.Server.DNS.WMI.DS
#
# Purpose: DNS Server DNS WMI DataSource
#
# File: Microsoft.Windows.Server.DNS.WMI.DS.ps1
#*************************************************************************
Function Start-Initialization
{
Set-Variable momApi -value $null -Scope Script
Set-Variable WMIProperty -value "EventLogLevel" -Scope Script -Option Constant
Set-Variable WMINamespace -value "root/MicrosoftDNS" -Scope Script -Option Constant
Set-Variable WMIClass -value "MicrosoftDNS_Server" -Scope Script -Option Constant
Set-Variable WMIQuery -value "SELECT EventLogLevel FROM MicrosoftDNS_Server" -Scope Script -Option Constant

}

Function Start-SCOMobjectsInitialization
{
try
{
$Script:momApi = New-Object -ComObject Mom.ScriptAPI -ErrorAction Stop
}
catch
{
if ($null -eq $Script:momApi)
{
exit
}

}

}

Function Get-WMIProbe
{
$ErrorMessage = "No Errors"
$ErrorNumber = 0
$double = 0

try
{

Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$objects = Get-CimInstance -CimSession $cimsession -Class $Script:WMIClass -Namespace $Script:WMINamespace -Property $Script:WMIProperty -ErrorAction Stop
}
catch
{
$objects = Get-WMIObject -Class $Script:WMIClass -Namespace $Script:WMINamespace -Property $Script:WMIProperty -ErrorAction Stop
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}

if($null -eq $objects)
{
$ErrorMessage = "Zero items in record set"
$ErrorNumber = 1
Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null
return
}

foreach ($object in $objects)
{
if ($null -eq $object.EventLogLevel)
{
$ErrorMessage = "Zero items in record set"
$ErrorNumber = 2
Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null
return

}

if (-Not [double]::TryParse($object.EventLogLevel,[ref]$double))
{
$ErrorMessage = "EventLogLevel is not numeric"
$ErrorNumber = 3
Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null
return

}

}

Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null

}
catch
{
Get-PropertyBag -Exception $_.Exception

}
}


Function Get-PropertyBag ([String]$ErrorMessage = [String]::Empty,$Exception,$ErrorNumber = $null)
{
if ($null -eq $Script:momApi)
{
return
}

$sError = ""
$sErrorNumber = "0x0"

try
{
$bag = $Script:momApi.CreatePropertyBag()

if (-Not [String]::IsNullOrEmpty($Exception.Message))
{
$sError = $Exception.Message
}
else
{
$sError = $ErrorMessage
}

if (-Not [String]::IsNullOrEmpty($Exception.ErrorCode))
{
$sErrorNumber = "0x" + $Exception.ErrorCode.ToString("x")
}
else
{
if (-Not [String]::IsNullOrEmpty($Exception.HResult))
{
$sErrorNumber = "0x" + $Exception.HResult.ToString("x")
}
else
{
if ($null -ne $ErrorNumber)
{
$sErrorNumber = "0x" + $ErrorNumber.ToString("x")
}

}
}


$bag.AddValue("WMINamespace",$Script:WMINamespace)
$bag.AddValue("WMIQuery",$Script:WMIQuery)
$bag.AddValue("ErrorMessage",$sError)
$bag.AddValue("ErrorNumber",$sErrorNumber)

$bag
}
catch
{

}


}

Function Import-CmdLets ()
{
try
{
$module = Get-Module -Name "CimCmdlets"
if ($null -eq $module)
{
Import-Module CimCmdlets
}
}
catch [System.IO.FileNotFoundException]
{
$ErrorMessage = "Cim cmdlets doesn't exist."
$ErrorNumber = 4
Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null
exit
}
catch
{
$ErrorMessage = $_.Exception.Message
$ErrorNumber = 5
Get-PropertyBag -ErrorMessage $ErrorMessage -ErrorNumber $ErrorNumber -Exception $null
Exit
}
}
Function Load-CimModules
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$CimModule = Get-Module CimCmdlets

if ($null -eq $CimModule)
{
Import-Module CimCmdlets
$error.Clear()

}
}
$ErrorActionPreference = "Stop"

Start-Initialization
Start-SCOMobjectsInitialization
Import-CmdLets
Get-WmiProbe

</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PS">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>