Datakälla för allmän identifiering

LW.Microsoft.Windows.Server.Generic.Discovery.DataSource (DataSourceModuleType)

Den här datakällan körs mot varje Windows Server-dator (2008R2 till 2016) och söker efter olika serverroller.

Knowledge Base article:

Sammanfattning

Denna datakälla används för att fastställa installationen av specifika Windows Server-roller av uppdaterings- och rekommendationsfunktionen.

Konfiguration

Intervall i sekunder: Hur ofta (i sekunder) värdet ska kontrolleras.

Tidsgräns i sekunder: Hur lång tid det tar (i sekunder) för att modulen ska avsluta sin körning.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.Discovery.Data

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Intervall (sek)
TimeoutSecondsint$Config/TimeoutSeconds$Tidsgräns i sekunder

Source Code:

<DataSourceModuleType ID="LW.Microsoft.Windows.Server.Generic.Discovery.DataSource" Accessibility="Public" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:unsignedInt"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="ComputerPrincipalName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:unsignedInt"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PowerShellDiscoveryProbe" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>"Lightweight generic discovery script"</ScriptName>
<ScriptBody><Script>
param ([String] $sourceID, [String] $managedEntityID, [String] $computerName)
#Copyright (c) Microsoft Corporation. All rights reserved.
#*************************************************************************
#Author - Arpit Mittal
#ScriptName: "Server2016Roles.ps1"$
#Purpose: This script along with ServerOSVersions.ps1 will discover installed server roles
# on the Windowse Server 2016.
#*************************************************************************

$windowsFeatureTable = @{}
$classMPElementTable = @{}
$classCategoryTable = @{}

#Get-WindowsFeature Discoveries
#IIS
$windowsFeatureTable.Add("LW.Microsoft.Windows.InternetInformationServices.6.4.ServerRole","Web-Server")
$classMPElementTable.Add("LW.Microsoft.Windows.InternetInformationServices.6.4.ServerRole","`$MPElement[Name='LW.Microsoft.Windows.InternetInformationServices.6.4.ServerRole']$")
$classCategoryTable.Add("LW.Microsoft.Windows.InternetInformationServices.6.4.ServerRole","IIS 2016+")

#Print Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.6.4.PrintServerRole","Print-Services")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.6.4.PrintServerRole","`$MPElement[Name='LW.Microsoft.Windows.Server.6.4.PrintServerRole']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.6.4.PrintServerRole","Print Server 2016+")

#ADFS
$windowsFeatureTable.Add("LW.Microsoft.ActiveDirectoryFederationServices.10.0.FederationServerSeed","ADFS-Federation")
$classMPElementTable.Add("LW.Microsoft.ActiveDirectoryFederationServices.10.0.FederationServerSeed","`$MPElement[Name='LW.Microsoft.ActiveDirectoryFederationServices.10.0.FederationServerSeed']$")
$classCategoryTable.Add("LW.Microsoft.ActiveDirectoryFederationServices.10.0.FederationServerSeed","Active Directory Federation Services 2016")

#ADRMS
$windowsFeatureTable.Add("LW.Microsoft.ADRMS.6.4.Server","ADRMS")
$classMPElementTable.Add("LW.Microsoft.ADRMS.6.4.Server","`$MPElement[Name='LW.Microsoft.ADRMS.6.4.Server']$")
$classCategoryTable.Add("LW.Microsoft.ADRMS.6.4.Server","Active Directory Rights Management Services 2016")

#DHCP
$windowsFeatureTable.Add("LW.Microsoft.Windows.DHCPServer.6.4.Server","DHCP")
$classMPElementTable.Add("LW.Microsoft.Windows.DHCPServer.6.4.Server","`$MPElement[Name='LW.Microsoft.Windows.DHCPServer.6.4.Server']$")
$classCategoryTable.Add("LW.Microsoft.Windows.DHCPServer.6.4.Server","DHCP Server 2016+")

#ADDS
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.10.0.AD.GlobalCatalogServerRole","AD-Domain-Services")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.10.0.AD.GlobalCatalogServerRole","`$MPElement[Name='LW.Microsoft.Windows.Server.10.0.AD.GlobalCatalogServerRole']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.10.0.AD.GlobalCatalogServerRole","Active Directory Domain Services 2016")

#Failover Clustering
$windowsFeatureTable.Add("LW.Microsoft.Windows.6.4.Cluster.Node","Failover-Clustering")
$classMPElementTable.Add("LW.Microsoft.Windows.6.4.Cluster.Node","`$MPElement[Name='LW.Microsoft.Windows.6.4.Cluster.Node']$")
$classCategoryTable.Add("LW.Microsoft.Windows.6.4.Cluster.Node","Windows Server Cluster 2016+")

#File and iSCSI services
$windowsFeatureTable.Add("LW.Microsoft.Windows.FileServices.Service.iSCSITarget.6.3","File-Services")
$classMPElementTable.Add("LW.Microsoft.Windows.FileServices.Service.iSCSITarget.6.3","`$MPElement[Name='LW.Microsoft.Windows.FileServices.Service.iSCSITarget.6.3']$")
$classCategoryTable.Add("LW.Microsoft.Windows.FileServices.Service.iSCSITarget.6.3","File Services 2016+")

#NLB
$windowsFeatureTable.Add("LW.Microsoft.Windows.NetworkLoadBalancing.6.4.ServerRole","NLB")
$classMPElementTable.Add("LW.Microsoft.Windows.NetworkLoadBalancing.6.4.ServerRole","`$MPElement[Name='LW.Microsoft.Windows.NetworkLoadBalancing.6.4.ServerRole']$")
$classCategoryTable.Add("LW.Microsoft.Windows.NetworkLoadBalancing.6.4.ServerRole","Network Load Balancing 2016+")

#DNS
$windowsFeatureTable.Add("LW.Microsoft.Windows.DNSServer.2016.Server","DNS")
$classMPElementTable.Add("LW.Microsoft.Windows.DNSServer.2016.Server","`$MPElement[Name='LW.Microsoft.Windows.DNSServer.2016.Server']$")
$classCategoryTable.Add("LW.Microsoft.Windows.DNSServer.2016.Server","Domain Naming Service 2016+")

#ADCS
$windowsFeatureTable.Add("LW.Microsoft.Windows.CertificateServices.CARole.6.4","AD-Certificate")
$classMPElementTable.Add("LW.Microsoft.Windows.CertificateServices.CARole.6.4","`$MPElement[Name='LW.Microsoft.Windows.CertificateServices.CARole.6.4']$")
$classCategoryTable.Add("LW.Microsoft.Windows.CertificateServices.CARole.6.4","Active Directory Certificate Services 2016")

#Defender
$windowsFeatureTable.Add("LW.Microsoft.Windows.Defender.Role.2016","Windows-Defender")
$classMPElementTable.Add("LW.Microsoft.Windows.Defender.Role.2016","`$MPElement[Name='LW.Microsoft.Windows.Defender.Role.2016']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Defender.Role.2016","Defender 2016")

#Windows Essentials Role
$windowsFeatureTable.Add("LW.Microsoft.Windows.Essentials.2016","ServerEssentialsRole")
$classMPElementTable.Add("LW.Microsoft.Windows.Essentials.2016","`$MPElement[Name='LW.Microsoft.Windows.Essentials.2016']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Essentials.2016","Essentials 2016")

#Branch Cache 2016
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.Branch.Cache.2016","BranchCache")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.Branch.Cache.2016","`$MPElement[Name='LW.Microsoft.Windows.Server.Branch.Cache.2016']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.Branch.Cache.2016","Branch Cache 2016")

#LW.Microsoft.HyperV.2016
$windowsFeatureTable.Add("LW.Microsoft.HyperV.2016","Msvm_VirtualSystemManagementService")
$classMPElementTable.Add("LW.Microsoft.HyperV.2016","`$MPElement[Name='LW.Microsoft.HyperV.2016']$")
$classCategoryTable.Add("LW.Microsoft.HyperV.2016","Hyper-V 2016")

#LW.Microsoft.2016.RemoteDesktopServices
$windowsFeatureTable.Add("LW.Microsoft.2016.RemoteDesktopServices","Remote-Desktop-Services")
$classMPElementTable.Add("LW.Microsoft.2016.RemoteDesktopServices","`$MPElement[Name='LW.Microsoft.2016.RemoteDesktopServices']$")
$classCategoryTable.Add("LW.Microsoft.2016.RemoteDesktopServices","Remote Desktop Services 2016")

function LogWrite
{
Param([string]$logString)
$script:logMessage += $logString
}

#scriptStartTime will help in calculating script run time
$scriptStartTime = Get-Date
$script:logMessage = ''
$GuestOS = ''
$wmiOS = (Get-WmiObject -Class Win32_OperatingSystem).caption
if (-not ([string]::IsNullOrEmpty($wmiOS)))
{
$GuestOS = $wmiOS
}

LogWrite "`nServer2016Roles::Starting Server2016Roles script."

if(($SourceId -eq $null) -or ($ManagedEntityId -eq $null) -or ($computerName -eq $null))
{
LogWrite "`nServer2016Roles::SourceId, ManagedEntityId or Computer name is null. Exiting script."
Exit -1
}

#Create discovery property bag only once as we can't return multiple property bags
$api = new-object -comObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

#get all server roles information in single shot
$allInstalledFeatures = get-windowsfeature | ?{$_.InstallState -eq "Installed"}

#Iterate through discovery method table
if($windowsFeatureTable -eq $null)
{
#Code shouldn't come here
LogWrite "`nServer2016Roles::Windows feature table is empty. Exiting the script."
Exit -1
}

foreach ($classDetails in $windowsFeatureTable.GetEnumerator())
{
$className = $classDetails.Name
$serverRoleName = $classDetails.Value

if($serverRoleName -eq $null)
{
continue
}

$getFeatureDetails = $allInstalledFeatures | ?{$_.Name -eq $serverRoleName}

#getfeaturedetails will be null if supported role in NOT present in installed list
if(($getFeatureDetails -ne $null) -and ($classMPElementTable.Item($className) -ne $null))
{
LogWrite "`nCreating class instance for class $className"
$instance = $discoveryData.CreateClassInstance($classMPElementTable.Item($className))
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $computerName)
$instance.AddProperty("$MPElement[Name='LW.Base.Microsoft.Windows.ComputerRole.Category']/CategoryName$", $classCategoryTable.Item($className))
$instance.AddProperty("$MPElement[Name='LW.Base.Microsoft.Windows.ComputerRole.Category']/GuestOS$", $GuestOS)
$discoveryData.AddInstance($instance)
}
}

$scriptEndTime = Get-Date
$totalScriptRunTime = ($scriptEndTime - $scriptStartTime) | select-object TotalSeconds
$totalScriptRunTime = $totalScriptRunTime.TotalSeconds
LogWrite "`n Total time taken to run the script $totalScriptRunTime"

#Log an event after running the script
$api.LogScriptEvent("Server2016Roles.ps1", 5001, 0, $script:logMessage)

#Return discovery property bag
$discoveryData</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>computerName</Name>
<Value>$Config/ComputerPrincipalName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>false</StrictErrorHandling>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PowerShellDiscoveryProbe">
<Node ID="Scheduler"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>