Agent Relationship Discovery Data Source

Microsoft.SystemCenter.ADManagedComputerDiscovery (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<DataSourceModuleType ID="Microsoft.SystemCenter.ADManagedComputerDiscovery" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</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="DataSource" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverAgentRelationshipSettings.ps1</ScriptName>
<ScriptBody><Script>

param($SourceType, $SourceId , $ManagedEntityId ,$ComputerIdentity ,$ManagementGroupName)
function PrintError($error)
{
Write ("============================= BEGIN ERROR =================================\n");
Write ("Error Type : " + $error);
Write ("Error Number : " + $Error[0].Exception.GetType().FullName);
#Write ("Error Code : " + ($error.number -band 0xFFFF));
#Write ("Win32 Facility : " + ($error.number -shr 16 -band 0x1FFF));
Write ("Error Source : " + $error.Source);
Write ("Error Description : " + $error.description);
Write ("============================== END ERROR ==================================\n");
}

function SafeRegRead($registryPath)
{
try
{
$oReg = Get-ItemProperty $registryPath -ErrorAction stop;
return $oReg.EnableADIntegration
}
catch
{
switch ($Error[0].Exception.GetType().FullName)
{
# HRESULT 0x80070002: ERROR_FILE_NOT_FOUND - Severity: FAILURE (1), FACILITY_WIN32 (0x7), Code 0x2
# If UseActiveDirectory RegValue DOES NOT EXIST the agent for this Management Group IS AD Integrated
'System.Management.Automation.ItemNotFoundException'
{
Write("Could not find \$registryPath \n");
Exit 1;
break;
}
default {
PrintError($error);
}
}
}
}

Write("SourceId " + $SourceId);
Write("ManagedEntityId: " + $ManagedEntityId);
Write("ComputerIdentity: " + $ComputerIdentity);
Write("ManagementGroupName: " + $ManagementGroupName);
$oAPI = new-object -comobject 'MOM.ScriptAPI'
$SCRIPT_NAME = "DiscoverAgentRelationshipSettings.ps1";
$ENU_MESSAGE_BASE = "This script discovers AgentRelationshipSettings objects\n\r";

$EVENTLOG_SUCCESS = 0x0000; # Information event */
$EVENTLOG_AUDIT_FAILURE = 0x0010; # Failure Audit event */
$EVENTLOG_AUDIT_SUCCESS = 0x0008; # Success Audit event */
$EVENTLOG_ERROR_TYPE = 0x0001; # Error event */
$EVENTLOG_INFORMATION_TYPE = 0x0004; # Information event */
$EVENTLOG_WARNING_TYPE = 0x0002; # Warning event */

$MOMCONNECTOR_CLSID = "{534E71F9-7970-42D6-921F-59CFB873855F}"; # MomConnecotr CLSID */

$ConnectorCLSIDRegValue = "HKLM:\SYSTEM\CurrentControlSet\services\HealthService\Parameters\Management Groups\" + $ManagementGroupName
$EnableADIntegrationRegValue = "HKLM:\SYSTEM\CurrentControlSet\Services\HealthService\Parameters\ConnectorManager";
$UseActiveDirectoryRegValue = "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\" + $ManagementGroupName

try
{
$ConnectorCLSID = Get-ItemProperty $ConnectorCLSIDRegValue -ErrorAction stop
$ConnectorCLSID = $ConnectorCLSID.'Connector CLSID'
}
catch
{
switch ($Error[0].Exception.GetType().FullName)
{
# HRESULT 0x80070002: ERROR_FILE_NOT_FOUND - Severity: FAILURE (1), FACILITY_WIN32 (0x7), Code 0x2
# If ConnectorCLSID RegValue DOES NOT EXIST, the agent for this Management Group IS NOT AD Integrated
'System.Management.Automation.ItemNotFoundException' {
$ConnectorCLSID = "";
break;
}
default {
PrintError($Error);
throw($Error);
}
}
}
Write-Host "`nConnectorCLSID value: " + $ConnectorCLSID
if ($ConnectorCLSID -eq $MOMCONNECTOR_CLSID)
{
$EnableADIntegration = SafeRegRead($EnableADIntegrationRegValue);

try
{
$UseActiveDirectory = Get-ItemProperty $UseActiveDirectoryRegValue -ErrorAction stop;
$UseActiveDirectory = $UseActiveDirectory."UseActiveDirectory"
}
catch
{
switch ($Error[0].Exception.GetType().FullName)
{
# HRESULT 0x80070002: ERROR_FILE_NOT_FOUND - Severity: FAILURE (1), FACILITY_WIN32 (0x7), Code 0x2
# If UseActiveDirectory RegValue DOES NOT EXIST the agent for this Management Group IS AD Integrated
'System.Management.Automation.ItemNotFoundException'
{
$UseActiveDirectory = "TRUE"
break;
}
default {
PrintError($error);
throw($error);
}
}
}

if($UseActiveDirectory -eq "0")
{
$UseActiveDirectory = "FALSE"
}else{
$UseActiveDirectory = "TRUE"
}

if($EnableADIntegration -eq "0")
{
$EnableADIntegration = "FALSE"
}else{
$EnableADIntegration = "TRUE"
}

Write-Host ("`nEnableADIntegration value: " + $EnableADIntegration);
Write-Host ("UseActiveDirectory value: " + $UseActiveDirectory);


if (($EnableADIntegration -ne $null) -and ($UseActiveDirectory -ne $null))
{
$oDiscovery = $oAPI.CreateDiscoveryData($SourceType, $SourceId, $ManagedEntityId);

$oHealthService = $oDiscovery.CreateClassInstance("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']$");
$oHealthService.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerIdentity);
$oHealthService.AddProperty("$MPElement[Name='SCLibrary!Microsoft.SystemCenter.HealthService']/ActiveDirectoryManaged$", $UseActiveDirectory);

$oDiscovery.AddInstance($oHealthService);
return $oDiscovery
}
}

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceType</Name>
<Value>0</Value>
</Parameter>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>ComputerIdentity</Name>
<Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>ManagementGroupName</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>