Exchange.Queues.Server.Discovery (Discovery)

Element properties:

TargetMicrosoft.Exchange.15.Server
EnabledTrue
Frequency86400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="Exchange.Queues.Server.Discovery" Enabled="true" Target="Exchange2013!Microsoft.Exchange.15.Server" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Exchange.Queues.Server"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>86400</IntervalSeconds>
<SyncTime/>
<ScriptName>Exchange.Queues.Server.Discovery.ps1</ScriptName>
<ScriptBody><Script>
#=================================================================================
# Exchange 2013 (and later) Queue Server Role Discovery Script
#
# Author: Kevin Holman
# v1.1
#=================================================================================
param($SourceId,$ManagedEntityId,[string]$ComputerName,[string]$MGName,[string]$ExchServerName)


# Manual Testing section - put stuff here for manually testing script - typically parameters:
#=================================================================================
# $SourceId = '{00000000-0000-0000-0000-000000000000}'
# $ManagedEntityId = '{00000000-0000-0000-0000-000000000000}'
# $ComputerName = "computername.domain.com"
# $MGName = "MGNAME"
#=================================================================================


# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
# ScriptName should be the same as the ID of the module that the script is contained in
$ScriptName = "Exchange.Queues.Server.Discovery.ps1"
$EventID = "1470"
#=================================================================================


# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`nScript is starting. `nRunning as ($whoami). `nMGName: ($MGName). Exchange Server Name: ($ExchServerName).")
#=================================================================================


# Discovery Script section - Discovery scripts get this
#=================================================================================
# Load SCOM Discovery module
$DiscoveryData = $momapi.CreateDiscoveryData(0,$SourceId,$ManagedEntityId)
#=================================================================================


# Begin MAIN script section
#=================================================================================
#Load the Exchange snapin if not exists
IF (!(Get-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue))
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}

# Get the Exchange Server object
$ExchangeServerObj = Get-ExchangeServer -Identity $ExchServerName
IF ($ExchangeServerObj -eq $null)
{
$momapi.LogScriptEvent($ScriptName,$EventID,1,"`nFATAL ERROR - cannot get Exchange Server object via PowerShell. `nTerminating Script. `nError is ($Error).")
EXIT
}

IF ($ExchangeServerObj.IsHubTransportServer -eq "True" -or $ExchangeServerObj.IsEdgeServer -eq "True")
{
#This is an Exchange 2013 or later Hub or Edge server with queues
$instance = $DiscoveryData.CreateClassInstance("$MPElement[Name='Exchange.Queues.Server']$")
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName)
$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $ComputerName)
$instance.AddProperty("$MPElement[Name='Exchange2013!Microsoft.Exchange.15.Server']/Name$", $ExchServerName)
$DiscoveryData.AddInstance($instance)
}

# Return Discovery Items Normally
$DiscoveryData
# Return Discovery Bag to the command line for testing (does not work from ISE)
# $momapi.Return($DiscoveryData)
#=================================================================================


# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`nScript Completed. `nRuntime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</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>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>MGName</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
<Parameter>
<Name>ExchServerName</Name>
<Value>$Target/Property[Type="Exchange2013!Microsoft.Exchange.15.Server"]/Name$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>