Ogólne źródło danych odnajdywania

LW.Microsoft.Windows.Server.2012R2.Role.Discovery.DataSource (DataSourceModuleType)

To źródło danych jest uruchamiane dla każdego komputera z systemem Windows Server 2016 i sprawdza różne role serwera w wersji 2012 R2.

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$Interwał (s)
TimeoutSecondsint$Config/TimeoutSeconds$Limit czasu w sekundach

Source Code:

<DataSourceModuleType ID="LW.Microsoft.Windows.Server.2012R2.Role.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 2012R2 server roles discovery script"</ScriptName>
<ScriptBody><Script>
param ([String] $sourceID, [String] $managedEntityID, [String] $computerName)
#Copyright (c) Microsoft Corporation. All rights reserved.
#*************************************************************************
#Author - Arpit Mittal
#ScriptName: "Server2012R2Roles.ps1"$
#Purpose: This script along with ServerOSVersions.ps1 will discover installed server roles
# on the Windows Server 2012R2.
#*************************************************************************

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

#Get-WindowsFeature Discoveries
#AD Certificate Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.AD.Certificate.2012R2","AD-Certificate")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.AD.Certificate.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.AD.Certificate.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.AD.Certificate.2012R2","Active Directory Certification Services 2012/2012 R2")

#AD Federation Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.AD.Federation.2012R2","ADFS-Federation")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.AD.Federation.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.AD.Federation.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.AD.Federation.2012R2","Active Directory Federation Services 2012 R2")

#AD Right Management Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.AD.Rights.Management.2012R2","ADRMS")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.AD.Rights.Management.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.AD.Rights.Management.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.AD.Rights.Management.2012R2","Active Directory Rights Management Services 2012/2012 R2")

#DHCP
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.DHCP.2012R2","DHCP")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.DHCP.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.DHCP.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.DHCP.2012R2","DHCP Server")

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

#File Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.File.Services.2012R2","File-Services")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.File.Services.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.File.Services.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.File.Services.2012R2","File Services 2012 R2")

#Multi Tenant Remote Access
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.Remote.Access.2012R2","RemoteAccess")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.Remote.Access.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.Remote.Access.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.Remote.Access.2012R2","Remote Access 2012/2012 R2")

#Network Load Balancing
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.NLB.2012R2","NLB")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.NLB.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.NLB.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.NLB.2012R2","Network Load Balancing")

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

#Windows Deployment Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Deployment.Services.2012R2","WDS")
$classMPElementTable.Add("LW.Microsoft.Windows.Deployment.Services.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Deployment.Services.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Deployment.Services.2012R2","Windows Deployment Services 2012 R2")

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

#Windows Update Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Update.Services.2012R2","UpdateServices")
$classMPElementTable.Add("LW.Microsoft.Windows.Update.Services.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Update.Services.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Update.Services.2012R2","Windows Server Update Services 2012/2012 R2")

#Message Queuing Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.Queuing.2012R2","MSMQ")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.Queuing.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.Queuing.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.Queuing.2012R2","Message Queuing 2012 R2")

#Print Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.Print.Services.2012R2","Print-Server")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.Print.Services.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.Print.Services.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.Print.Services.2012R2","Print Server 2012/2012 R2")

#Hyper-V Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.HyperV.2012R2","Hyper-V")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.HyperV.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.HyperV.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.HyperV.2012R2","Hyper-V 2012 R2")

#Active Directory Lightweight Directory Services
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.AD.Lightweight.Directory.2012R2","ADLDS")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.AD.Lightweight.Directory.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.AD.Lightweight.Directory.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.AD.Lightweight.Directory.2012R2","Active Directory Lightweight Directory Services")

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

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

#Active Directory
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.ActiveDirectory.2012R2","AD-Domain-Services")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.ActiveDirectory.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.ActiveDirectory.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.ActiveDirectory.2012R2","Active Directory Domain Services 2008/2008R2/2012/2012R2")

#Web Application Proxy
$windowsFeatureTable.Add("LW.Microsoft.Windows.Server.WebApplicationProxy.2012R2","Web-Application-Proxy")
$classMPElementTable.Add("LW.Microsoft.Windows.Server.WebApplicationProxy.2012R2","`$MPElement[Name='LW.Microsoft.Windows.Server.WebApplicationProxy.2012R2']$")
$classCategoryTable.Add("LW.Microsoft.Windows.Server.WebApplicationProxy.2012R2","Web Application Proxy 2012 R2")

#LW.Microsoft.3rdParty.Savision.ActiveDirectory
$windowsFeatureTable.Add("LW.Microsoft.3rdParty.Savision.ActiveDirectory","AD-Domain-Services")
$classMPElementTable.Add("LW.Microsoft.3rdParty.Savision.ActiveDirectory","`$MPElement[Name='LW.Microsoft.3rdParty.Savision.ActiveDirectory']$")
$classCategoryTable.Add("LW.Microsoft.3rdParty.Savision.ActiveDirectory","Active Directory (by Savision)")

#LW.Microsoft.3rdParty.Savision.DHCP
$windowsFeatureTable.Add("LW.Microsoft.3rdParty.Savision.DHCP","DHCP")
$classMPElementTable.Add("LW.Microsoft.3rdParty.Savision.DHCP","`$MPElement[Name='LW.Microsoft.3rdParty.Savision.DHCP']$")
$classCategoryTable.Add("LW.Microsoft.3rdParty.Savision.DHCP","DHCP (by Savision)")

#LW.Microsoft.3rdParty.Savision.DNS
$windowsFeatureTable.Add("LW.Microsoft.3rdParty.Savision.DNS","DNS")
$classMPElementTable.Add("LW.Microsoft.3rdParty.Savision.DNS","`$MPElement[Name='LW.Microsoft.3rdParty.Savision.DNS']$")
$classCategoryTable.Add("LW.Microsoft.3rdParty.Savision.DNS","DNS (by Savision)")

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

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 "`nServer2012R2Roles::Starting Server2012R2Roles script."

if(($SourceId -eq $null) -or ($ManagedEntityId -eq $null) -or ($computerName -eq $null))
{
LogWrite "`nServer2012R2Roles::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 "`nServer2012R2Roles::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 server role is not installed or we are not supporting the installed role
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("Server2012R2Roles.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>