# Get the needed classes
$webApplicationComponentClass = Get-SCOMClass -Name Microsoft.SystemCenter.ApplicationMonitoring.Net.WebApplicationComponent
$webServiceComponentClass = Get-SCOMClass -Name Microsoft.SystemCenter.ApplicationMonitoring.Net.AbstractWCFWebServiceComponent
# First, check to see if the passed in selected component is something with instances
$selectedComponentME = Get-SCOMClassInstance -Id $id
# Find the correct hosting relationship based on the class of the selected component
if ($selectedComponentME.IsInstanceOf($webServiceComponentClass))
{
$hostingRelationship = Get-SCOMRelationship -Name Microsoft.SystemCenter.Apm.AbstractWCFWebServiceComponentHostsApmAbstractWCFWebServiceApplicationComponent
$containingRelationship = Get-SCOMRelationship -Name Microsoft.SystemCenter.Apm.IIS2008.WCFWebServiceApplicationComponentContainsApmWebApplicationInstance
}
elseif ($selectedComponentME.IsInstanceOf($webApplicationComponentClass))
{
$hostingRelationship = Get-SCOMRelationship -Name Microsoft.SystemCenter.Apm.WebApplicationComponentHostsApmWebApplicationComponent
$containingRelationship = Get-SCOMRelationship -Name Microsoft.SystemCenter.Apm.AbstractWebApplicationComponentContainsApmWebApplicationInstance
}
else
{
# Only the above 2 classes have 'instances'. Clear the collection and return.
$ScriptContext.ReturnCollection.Clear()
return
}