Microsoft.Exchange.2010.CommonDomainController.DiscoveryDS (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterDiscoveryDataSource Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
VerboseLoggingbool$Config/VerboseLogging$

Source Code:

<DataSourceModuleType ID="Microsoft.Exchange.2010.CommonDomainController.DiscoveryDS" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InstallPath" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="VerboseLogging" type="xsd:boolean"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="VerboseLogging" Selector="$Config/VerboseLogging$" ParameterType="bool"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterDiscoveryDataSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\System32\WindowsPowerShell\v1.0\powershell.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine> -Command "&amp; '$File/MicrosoftExchangeDomainControllerDiscovery.ps1$'" 0 '$MPElement$' '$Target/Id$' '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$' '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$' '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/ActiveDirectorySite$' '$Config/VerboseLogging$'</CommandLine>
<TimeoutSeconds>1800</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>MicrosoftExchangeDomainControllerDiscovery.ps1</Name>
<Contents><Script>
# This script discovers the DC instances for a server and creates the relationships.
$EXPECTED_ARGUMENT_COUNT = 7;
$UNEXPECTED_ARGUMENT_COUNT_ERROR_ID = 101;
$UNEXPECTED_ERROR_ID = 102;
$SKIPPED_RELATIONSHIP_CREATION_WARNING_ID = 103;
$COMMAND_NOT_FOUND_WARNING_ID = 106;

$DISCOVERY_STARTED_INF_ID = 1470;
$DISCOVERY_ENDED_INF_ID = 1471;
$DISCOVERY_PROGRESS_INF_ID = 1472;

$EVENT_SOURCE = "MicrosoftExchangeDomainControllerDiscovery.ps1";
$EVENT_TYPE_ERROR = 1;
$EVENT_TYPE_WARNING = 2;
$EVENT_TYPE_INFORMATION = 4;

$infoOutput = "Domain Controller Discovery script `n" `
+ " Message: ";

# Create the MOM Scripting API object.
$api = New-Object -comObject "MOM.ScriptAPI";

$arguments = "";
for ($i = 0; $i -lt $Args.Count; $i++)
{
$arguments += " ""$($Args[$i])""";
}

if ($Args.Count -ne $EXPECTED_ARGUMENT_COUNT)
{
$api.LogScriptEvent(
$EVENT_SOURCE,
$UNEXPECTED_ARGUMENT_COUNT_ERROR_ID,
$EVENT_TYPE_ERROR,
"Expected " + $EXPECTED_ARGUMENT_COUNT + " arguments. But there were " + $Args.Count + " arguments. Exiting script.`n Arguments: " + $arguments);

exit -1;
}

# Assign global variables to parameters passed in from the command line.
#
$sourceType = $Args[0];
$sourceId = $Args[1];
$managedEntityId = $Args[2];
$computerPrincipalName = $Args[3];
$computerNetbiosName = $Args[4];
$computerActiveDirectorySite = $Args[5];
$verboseLoggingString = $Args[6];

# Log to EventLog if verboseLogging is set
function LogEvent($eventId, $eventType, $message)
{
if ($verboseLoggingString -eq "true")
{
$api.LogScriptEvent($EVENT_SOURCE, $eventId, $eventType, $message);
}
}

function Main()
{
LogEvent $DISCOVERY_STARTED_INF_ID $EVENT_TYPE_INFORMATION ($infoOutput + "Discovery Script started.`n Arguments: " + $arguments)

# Create the discovery data object for adding discovered instances.
$discoveryData = $api.CreateDiscoveryData($sourceType, $sourceId, $managedEntityId);
$commonRoleName = $computerNetbiosName + " (Common) - " + $computerActiveDirectorySite;

# ----------------------------------------------------------------------
# First get the essential objects related to this server.
# We will use these for creating classes in the next section.
# ----------------------------------------------------------------------
#
# This script discovers only the Domain Controllers that are insite for current machine.
# Out of site DCs are not used in regular operation. So those are ignored. (see E15 43434)
# Get the FQDNs in an array of strings. All have to be lowercased.
$ADSite = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite();
# DomainController.Name is fqdn
$dcNames = $ADSite.Servers | % { $_.Name.tolower() } | sort;

# ----------------------------------------------------------------------
# Create the CommonActiveDirectoryAccess instance (key Property=ComponentName)
# ADH_3
# one per Exchange Server
# ----------------------------------------------------------------------
$oCommonADAccess = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Exchange.2010.CommonActiveDirectoryAccess']$");
$oCommonADAccess.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerPrincipalName);
$oCommonADAccess.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Component']/ComponentName$", "AD Access - " + $commonRoleName);
$oCommonADAccess.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.ServerRole']/RoleName$", $commonRoleName);
$oCommonADAccess.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Component']/InstanceName$", "AD Access - " + $computerNetbiosName);
$discoveryData.AddInstance($oCommonADAccess);

# ServiceName is a key property.
# ADH_4
# one class per site (service level class). i.e. there will be exactly one service level instance of this class.
$oCommonADAccessService = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Exchange.2010.CommonActiveDirectoryAccessService']$");
$oCommonADAccessService.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/ServiceName$", "AD Access Service - " + $computerActiveDirectorySite);
$oCommonADAccessService.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/InstanceName$", "AD Access Service - " + $computerActiveDirectorySite);
$oCommonADAccessService.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/ActiveDirectorySite$", $computerActiveDirectorySite);
$discoveryData.AddInstance($oCommonADAccessService);

$ServiceContainsCommonADAccess = $discoveryData.CreateRelationshipInstance("$MPElement[Name='ExchangeReverseRollup_Microsoft.Exchange.2010.CommonActiveDirectoryAccessService.Contains.Microsoft.Exchange.2010.CommonActiveDirectoryAccess']$");
$ServiceContainsCommonADAccess.Source = $oCommonADAccessService;
$ServiceContainsCommonADAccess.Target = $oCommonADAccess;
$discoveryData.AddInstance($ServiceContainsCommonADAccess);

# ----------------------------------------------------------------------
# Create the DomainController classes.
# ----------------------------------------------------------------------
$dcNames | foreach {
# Per E14 bug 161851, make sure the instance name is not empty.
# We have seen cases where this is an empty string and causing discovery to fail.
if (![string]::IsNullOrEmpty($_))
{
# ServiceName is a key property, we need to make this entity specific for this AD site by uniquely identify it with the AD site in its name.
# ADH_1
# one class per DC &amp; per site (service level class). i.e. there will be a service level instance of this class for each DC.
$dcServiceName = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Exchange.2010.CommonADAccessDomainControllerService']$");
$dcServiceName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/ServiceName$", "Domain Controller Service (" + $_ + ") - " + $computerActiveDirectorySite);
$dcServiceName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/InstanceName$", $_);
$dcServiceName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Service']/ActiveDirectorySite$", $computerActiveDirectorySite);
$discoveryData.AddInstance($dcServiceName);

# ADH_2
# one class per DC &amp; per Exchange Server
$discoverDcName = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Exchange.2010.CommonDomainController']$");
$discoverDcName.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerPrincipalName);
$discoverDcName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Component']/ComponentName$", "Domain Controller (" + $_ + ") - " + $commonRoleName);
$discoverDcName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.ServerRole']/RoleName$", $commonRoleName);
$discoverDcName.AddProperty("$MPElement[Name='Microsoft.Exchange.2010.Component']/InstanceName$", $_);
$discoveryData.AddInstance($discoverDcName);

$dcServiceContainsDcInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name='ExchangeReverseRollup_Microsoft.Exchange.2010.CommonADAccessDomainControllerService.Contains.Microsoft.Exchange.2010.CommonDomainController']$");
$dcServiceContainsDcInstance.Source = $dcServiceName;
$dcServiceContainsDcInstance.Target = $discoverDcName;
$discoveryData.AddInstance($dcServiceContainsDcInstance);

# setup relationship between CommonActiveDirectoryAccess &amp; CommonDomainController
$relCommonAdAccess_Contains_CommonDomainController = $discoveryData.CreateRelationshipInstance("$MPElement[Name='ExchangeReverseRollup_Microsoft.Exchange.2010.CommonActiveDirectoryAccess.Contains.Microsoft.Exchange.2010.CommonDomainController']$");
$relCommonAdAccess_Contains_CommonDomainController.Source = $oCommonADAccess;
$relCommonAdAccess_Contains_CommonDomainController.Target = $discoverDcName;
$discoveryData.AddInstance($relCommonAdAccess_Contains_CommonDomainController);
}
}

$api.Return($discoveryData);

LogEvent $DISCOVERY_ENDED_INF_ID $EVENT_TYPE_INFORMATION ($infoOutput + "Exiting Discovery.")

trap [System.Management.Automation.CommandNotFoundException]
{
trap
{
$api.LogScriptEvent(
$EVENT_SOURCE,
$UNEXPECTED_ERROR_ID,
$EVENT_TYPE_ERROR,
$_.Exception);
exit -1;
}
}
}

Main;

trap
{
$api.LogScriptEvent(
$EVENT_SOURCE,
$UNEXPECTED_ERROR_ID,
$EVENT_TYPE_ERROR,
$_.Exception);
exit -1;
}
</Script></Contents>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>