Découverte des étendues DHCP 2016 et versions ultérieures avec pagination

Microsoft.Windows.DHCPServer.10.0.Scopes.Paging.DiscoveryProvider (DataSourceModuleType)

Cette source de données découvre les étendues DHCP 2016 et versions ultérieures à l’aide de la pagination pour les grandes quantités.

Knowledge Base article:

Résumé

Ce module de source de données découvre des étendues d’après des paramètres de pagination donnés dans Windows Server 2016 et versions ultérieures avec la fonctionnalité DHCP activée.

Configuration

Intervalle en secondes : Fréquence (en secondes) à laquelle la valeur doit être vérifiée.

Heure de la synchronisation : Heure de synchronisation pour l’exécution du module.

Délai d’expiration (secondes) : Délai d'attente (en secondes) jusqu'à la fin d'exécution du module.

Ligne initiale : Délai d’attente (en secondes) de la fin de l’exécution du module.

Ligne finale : Délai d’attente (en secondes) de la fin de l’exécution du module.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS1 DataSource System.Discovery.Scheduler Default
PS2 ProbeAction Microsoft.Windows.PowerShellDiscoveryProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
InitialRowint$Config/InitialRow$Pourcentage initialIl s’agit du pourcentage initial à retourner dans la découverte.
FinalRowint$Config/FinalRow$Pourcentage finalIl s’agit du pourcentage final à retourner dans la découverte.
IntervalSecondsint$Config/IntervalSeconds$Intervalle en secondesÀ quelle fréquence (en secondes) la valeur doit être échantillonnée.
SyncTimestring$Config/SyncTime$Heure de synchronisationHeure de synchronisation pour l’exécution du module.
TimeoutSecondsint$Config/TimeoutSeconds$Délai d’expiration (secondes)Délai prévu (en secondes) pendant lequel le module attend pour terminer l'exécution.

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.DHCPServer.10.0.Scopes.Paging.DiscoveryProvider" Accessibility="Public">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="PrincipalName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="NetbiosComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="InitialRow" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="FinalRow" type="xsd:integer"/>
<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="InitialRow" Selector="$Config/InitialRow$" ParameterType="int"/>
<OverrideableParameter ID="FinalRow" Selector="$Config/FinalRow$" ParameterType="int"/>
<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 TypeID="System!System.Discovery.Scheduler" ID="DS1">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe" ID="PS2">
<ScriptName>DiscoverDHCPScopes.10.0.WithPaging.ps1</ScriptName>
<ScriptBody><Script>

param ([String] $ElementID, [String] $TargetID, [String] $PrincipalName, [String] $NetbiosComputerName, [Int] $InitialRow, [Int] $FinalRow)

$SCRIPT_NAME = "DiscoverDHCPScopes.10.0.WithPaging"
$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


$ComputerKey = "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$"
$DisplayName = "$MPElement[Name='System!System.Entity']/DisplayName$"

$ServerName = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Server']/Name$"
$ComponentName = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.DHCPComponent']/Name$"
$DHCPType03 = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.IPv4Runtime']$"
$Name = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Server']/Name$"
$IPAddress = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Scope']/IPAddress$"
$SubnetMask = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Scope']/SubnetMask$"
$IsEnabled = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Scope']/IsEnabled$"
$OSCurrentVersion = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Scope']/OSCurrentVersion$"
$ScopeName = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Scope']/Name$"

$DHCPType01 = "$MPElement[Name='Microsoft.Windows.DHCPServer.10.0.IPv4Scope']$"
$DHCPType02 = "$MPElement[Name='Microsoft.Windows.DHCPServer.10.0.IPv6Scope']$"
$DHCPType04 = "$MPElement[Name='Microsoft.Windows.DHCPServer.10.0.IPv6Runtime']$"

$DHCPType05 = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Superscope']$"
$PrincNameProp = "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$"
$SuperScopeName = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Superscope']/Name$"
$SuperOSCurrVer = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Superscope']/OSCurrentVersion$"
$SuperScopeRel = "$MPElement[Name='DHCP!Microsoft.Windows.DHCPServer.Library.Contains.SuperscopeContainsScope']$"


Write-Host "$SCRIPT_NAME - Executing DHCP Scope Discovery Powershell Script"

$discoveryData = $momAPI.CreateDiscoveryData(0, $ElementID, $TargetID)

$CurrOS = Get-WmiObject -Namespace "root\cimv2" -Query "select Version from Win32_OperatingSystem"
$OSVer = $CurrOS.Version
$CurrVer = $OSVer.Split(".")
$OS = $CurrVer.Item(0) + "." + $CurrVer.Item(1)


$IPV4Scopes = Get-DhcpServerv4Scope
$IPV6Scopes = Get-DhcpServerv6Scope

if($IPV4Scopes -eq $null)
{
$IPV4ScopesCount = 0
}
else
{
if($IPV4Scopes.Count -eq $null)
{
$IPV4ScopesCount = 1
}
else
{
$IPV4ScopesCount = $IPV4Scopes.Count
}
}

if($IPV6Scopes -eq $null)
{
$IPV6ScopesCount = 0
}
else
{
if($IPV6Scopes.Count -eq $null)
{
$IPV6ScopesCount = 1
}
else
{
$IPV6ScopesCount = $IPV6Scopes.Count
}
}

if ($IPV4ScopesCount -eq 0 -and $IPV6ScopesCount -eq 0)
{
Write-Host "$SCRIPT_NAME - No DHCP Scopes installed in the Server"
$discoveryData
exit
}
else
{
$ArrSuperScopeObjts = @()
$ArrSuperScopeNames = @()


if ($IPV4ScopesCount -gt 0)
{
$targetIPV4Runtime = $discoveryData.CreateClassInstance($DHCPType03)
$targetIPV4Runtime.AddProperty($ComputerKey, $PrincipalName)
$targetIPV4Runtime.AddProperty($ServerName, $PrincipalName)
$targetIPV4Runtime.AddProperty($ComponentName, $PrincipalName + "-IPv4 Runtime")
$targetIPV4Runtime.AddProperty($DisplayName, "IPv4 Runtime" + " (" + $PrincipalName + ")")
$discoveryData.AddInstance($targetIPV4Runtime)

$SuperScopes = Get-DHCPServerv4Superscope

if($SuperScopes.Length -eq $null)
{
$SuperScopeCount = 1
}
else
{
$SuperScopeCount = $SuperScopes.Length
}


for ($itmSupScp=0; $itmSupScp -lt $SuperScopeCount; $itmSupScp++)
{
if($SuperScopes.Length -eq $null)
{
$ObjSuperScope = $SuperScopes
}
else
{
if($SuperScopes.Get($itmSupScp) -ne $null)
{
$ObjSuperScope = $SuperScopes.Get($itmSupScp)
}
}

if($ObjSuperScope.SuperscopeName.Length -gt 0)
{
$targetSuperScope = $discoveryData.CreateClassInstance($DHCPType05)

$targetSuperScope.AddProperty($PrincNameProp, $PrincipalName)
$targetSuperScope.AddProperty($ServerName, $PrincipalName)
$targetSuperScope.AddProperty($SuperScopeName, $ObjSuperScope.SuperscopeName)
$targetSuperScope.AddProperty($DisplayName, $ObjSuperScope.SuperscopeName + " (" + $PrincipalName + ")" )
$targetSuperScope.AddProperty($SuperOSCurrVer, $OSVer)

$ArrSuperScopeObjts += @($targetSuperScope)
$ArrSuperScopeNames += @($ObjSuperScope.SuperscopeName)

$discoveryData.AddInstance($targetSuperScope)

Write-Host "$SCRIPT_NAME - SuperScope Added to Discovery data"

}

}

[int]$IPV4Initial=0
[int]$IPV4Count=0
#New Scopes discovery
if(($IPV4ScopesCount -lt 10) -and ($InitialRow -eq 0))
{
$IPV4Initial= 1
$IPV4Count = $IPV4ScopesCount
}
else
{
if($IPV4ScopesCount -ge 10)
{
$IPV4Initial = if($InitialRow -eq 0){1}else{($InitialRow/100*$IPV4ScopesCount)+1}
$IPV4Count = ($FinalRow/100*$IPV4ScopesCount)
}
else #this is to shortcircuit the below for loop when the scopes count is &lt;10 and intiail row 0
{
$IPV4Initial=0
$IPV4Count=-1
}
}
for ($itmIPV4Scope=$IPV4Initial; $itmIPV4Scope -le $IPV4Count; $itmIPV4Scope++)
{
if($IPV4ScopesCount -eq 1)
{
$ObjIPV4Scope = $IPV4Scopes
}
else
{
if($IPV4Scopes.Get($itmIPV4Scope-1) -ne $null)
{
$ObjIPV4Scope = $IPV4Scopes.Get($itmIPV4Scope-1)
}
}

$targetIPV4Scope = $discoveryData.CreateClassInstance($DHCPType01)
$targetIPV4Scope.AddProperty($ComputerKey, $PrincipalName)
$targetIPV4Scope.AddProperty($ServerName, $PrincipalName)
$targetIPV4Scope.AddProperty($ComponentName, $PrincipalName + " - " + $ObjIPV4Scope.Name)
$targetIPV4Scope.AddProperty($DisplayName, $PrincipalName + " - " + $ObjIPV4Scope.Name)
$targetIPV4Scope.AddProperty($IPAddress, $ObjIPV4Scope.ScopeId.toString())
$targetIPV4Scope.AddProperty($SubnetMask, $ObjIPV4Scope.SubnetMask.toString())

if($ObjIPV4Scope.State -eq "Active")
{
$targetIPV4Scope.AddProperty($IsEnabled, $true)
}
else
{
$targetIPV4Scope.AddProperty($IsEnabled, $false)
}

$targetIPV4Scope.AddProperty($OSCurrentVersion, $OSVer)
$targetIPV4Scope.AddProperty($ScopeName, $ObjIPV4Scope.Name)

$discoveryData.AddInstance($targetIPV4Scope)
Write-Host "$SCRIPT_NAME - IPV4 Added to Discovery data"

$IndScope = $ArrSuperScopeNames.IndexOf($ObjIPV4Scope.SuperscopeName)

if($IndScope -ne -1)
{
$objSupScope = $ArrSuperScopeObjts[$IndScope]

$oRelationship = $discoveryData.CreateRelationshipInstance($SuperScopeRel)
$oRelationship.Source = $objSupScope
$oRelationship.Target = $targetIPV4Scope

$discoveryData.AddInstance($oRelationship)

Write-Host "$SCRIPT_NAME - SuperScope Relationship Added to Discovery data"
}
}

}

if ($IPV6ScopesCount -gt 0)
{
[int]$IPV6Initial=0
[int]$IPV6Count=0
$targetIPV6Runtime = $discoveryData.CreateClassInstance($DHCPType04)
$targetIPV6Runtime.AddProperty($ComputerKey, $PrincipalName)
$targetIPV6Runtime.AddProperty($ServerName, $PrincipalName)
$targetIPV6Runtime.AddProperty($ComponentName, $PrincipalName + "-IPv6 Runtime")
$targetIPV6Runtime.AddProperty($DisplayName, "IPv6 Runtime" + " (" + $PrincipalName + ")")
$discoveryData.AddInstance($targetIPV6Runtime)

#New Scopes discovery
if(($IPV6ScopesCount -lt 10) -and ($InitialRow -eq 0))
{
$IPV6Initial= 1
$IPV6Count = $IPV6ScopesCount
}
else
{
if($IPV6ScopesCount -ge 10)
{
$IPV6Initial = if($InitialRow -eq 0){1}else{($InitialRow/100*$IPV6ScopesCount)+1}
$IPV6Count = ($FinalRow/100*$IPV6ScopesCount)
}
else #this is to shortcircuit the below for loop when the scopes count is &lt;10 and intiail row 0
{
$IPV6Initial=0
$IPV6Count=-1
}
}

for ($itmIPV6Scope=$IPV6Initial; $itmIPV6Scope -le $IPV6Count; $itmIPV6Scope++)
{
if($IPV6ScopesCount -eq 1)
{
$ObjIPV6Scope = $IPV6Scopes
}
else
{
if($IPV6Scopes.Get($itmIPV6Scope-1) -ne $null)
{
$ObjIPV6Scope = $IPV6Scopes.Get($itmIPV6Scope-1)
}
}


$targetIPV6Scope = $discoveryData.CreateClassInstance($DHCPType02)
$targetIPV6Scope.AddProperty($ComputerKey, $PrincipalName)
$targetIPV6Scope.AddProperty($ServerName, $PrincipalName)
$targetIPV6Scope.AddProperty($ComponentName, $PrincipalName + " - " + $ObjIPV6Scope.Name)
$targetIPV6Scope.AddProperty($DisplayName, $PrincipalName + " - " + $ObjIPV6Scope.Name)
$targetIPV6Scope.AddProperty($IPAddress, $ObjIPV6Scope.Prefix.toString())
$targetIPV6Scope.AddProperty($SubnetMask, "")

if($ObjIPV6Scope.State -eq "Active")
{
$targetIPV6Scope.AddProperty($IsEnabled, $true)
}
else
{
$targetIPV6Scope.AddProperty($IsEnabled, $false)
}

$targetIPV6Scope.AddProperty($OSCurrentVersion, $OSVer)
$targetIPV6Scope.AddProperty($ScopeName, $ObjIPV6Scope.Name)

$discoveryData.AddInstance($targetIPV6Scope)
Write-Host "$SCRIPT_NAME - IPV6 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>PrincipalName</Name>
<Value>$Config/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>NetbiosComputerName</Name>
<Value>$Config/NetbiosComputerName$</Value>
</Parameter>
<Parameter>
<Name>InitialRow</Name>
<Value>$Config/InitialRow$</Value>
</Parameter>
<Parameter>
<Name>FinalRow</Name>
<Value>$Config/FinalRow$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PS2">
<Node ID="DS1"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>