Discover Relationship between Windows Computer with Baseboard Management Controller and SMASH Device

Microsoft.SystemCenter.OOB.BMCWindowsComputerContainsSMASHDevice.Discovery (Discovery)

Element properties:

TargetMicrosoft.SystemCenter.OOB.SMASHDevice
EnabledFalse
Frequency21600
RemotableFalse

Object Discovery Details:

Discovered relationships and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="Microsoft.SystemCenter.OOB.BMCWindowsComputerContainsSMASHDevice.Discovery" Enabled="false" Target="Microsoft.SystemCenter.OOB.SMASHDevice" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryRelationship TypeID="Microsoft.SystemCenter.OOB.BMCWindowsComputerContainsSMASHDevice"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>21600</IntervalSeconds>
<SyncTime/>
<ScriptName>BMCWindowsComputerContainsSMASHDevice.Discovery.ps1</ScriptName>
<ScriptBody><Script>

param($targetObjectId, $smBiosGuid, $discovery, $smashIP)

$global:eventMG = "."
$global:eventWorkflow = "Microsoft.SystemCenter.OOB.BMCWindowsComputerContainsSMASHDevice.Discovery"
$global:eventInstanceName = "$Target/Property[Type='System!System.Entity']/DisplayName$"
$global:eventInstanceId = "$Target/Id$"
function RaiseEvent($eventType, $eventNumber, $message)
{
$channel = "Operations Manager"
$source = "Health Service Modules Ex"
$eventLog = new-object System.Diagnostics.EventLog -ArgumentList @($channel)
$eventLog.Source = $source

$eventData = @()
$eventData += $global:eventMG
$eventData += $global:eventWorkflow
$eventData += $global:eventInstanceName
$eventData += $global:eventInstanceId
$eventData += $message
$eventData += $source

if($eventType -eq 0)
{
$eventType = [System.Diagnostics.EventLogEntryType]::Information
}
elseif($eventType -eq 1)
{
$eventType = [System.Diagnostics.EventLogEntryType]::Warning
}
elseif($eventType -eq 2)
{
$eventType = [System.Diagnostics.EventLogEntryType]::Error
}

$eventInstance = new-object System.Diagnostics.EventInstance -ArgumentList @($eventNumber, 0, $eventType)
$eventLog.WriteEvent($eventInstance, $eventData)
}

$script:ErrorActionPreference = "SilentlyContinue"
trap
{
RaiseEvent 1 10042 ("OOB MP BMC Windows computer contains smash device discovery got a script error: [" + $_.Exception.Message + "]")
throw $_.Exception.Message
}

function ConvertPart
{
$part = $args[0]
$result = ""
for($i = $part.Length - 1; $i -gt 0; $i = $i - 2)
{
$result = $result + $part[$i - 1] + $part[$i]
}
$result
}

function ConvertGuid
{
$guid = $args[0]
$guid = $guid.ToString()
$guidParts = $guid.Split("-")
$newGuid = ""
for($i = 0; $i -lt $guidParts.Length; $i++)
{
if($newGuid -ne "")
{
$newGuid = $newGuid + "-"
}
if($i -lt 3)
{
$newGuid = $newGuid + (ConvertPart $guidParts[$i])
}
else
{
$newGuid = $newGuid + $guidParts[$i]
}
}
$newGuid
}

$smashId = [Guid]$targetObjectId
$smashBiosGuid = ConvertGuid $smBiosGuid
$smashBiosGuidReserved = $smBiosGuid.ToString()
$bmcClassName = "Microsoft.SystemCenter.OOB.BMCWindowsComputer"
$bmcSMBiosGuidPropertyName = "UUID"
$bmcPrincipalNamePropertyName = "PrincipalName"

$OMPSInstallKey = "HKLM:\Software\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$regKey = get-item $OMPSInstallKey
$OMPSInstallPath = $regKey.GetValue("InstallDirectory")
$omModule = $OMPSInstallPath + "OperationsManager"
Import-Module -Name $omModule
Start-Sleep -s 20

$computerName = $env:ComputerName + "." + $env:FQDN
$mg = New-Object -TypeName "Microsoft.EnterpriseManagement.ManagementGroup" -ArgumentList @($computerName)

$bmcClass = $mg.GetMonitoringClasses($bmcClassName)[0]
$bmcComputers = $mg.GetMonitoringObjects($bmcClass)

$principalName = $null
foreach($bmcComputer in $bmcComputers)
{
if($bmcComputer -eq $null)
{
continue
}

$properties = $bmcComputer.GetProperties()
$isNeeded = $false
foreach($p in $properties)
{
if($p.Name -eq $bmcPrincipalNamePropertyName)
{
$principalName = $bmcComputer[$p].Value
}
elseif($p.Name -eq $bmcSMBiosGuidPropertyName)
{
if($bmcComputer[$p].Value -eq $smashBiosGuidReserved -or $bmcComputer[$p].Value -eq $smashBiosGuid)
{
$isNeeded = $true
}
else
{
break
}
}
}
if($isNeeded)
{
break
}
else
{
$principalName = $null
}
}

$api = New-Object -comObject "MOM.ScriptAPI"
$discoveryData = $null

if($principalName -ne $null)
{
$discoveryData = $api.CreateDiscoveryData(0, $discovery, $targetObjectId)
$sourceInstance = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.OOB.BMCWindowsComputer']$");
$sourceInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $principalName)
$targetInstance = $discoveryData.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.OOB.SMASHDevice']$");
$targetInstance.AddProperty("$MPElement[Name='Microsoft.SystemCenter.OOB.WSManDevice']/IP$", $smashIP)
$discoveryData.AddInstance($sourceInstance)
$discoveryData.AddInstance($targetInstance)
$relationship = $discoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.SystemCenter.OOB.BMCWindowsComputerContainsSMASHDevice']$")
$relationship.Source = $sourceInstance
$relationship.Target = $targetInstance
$discoveryData.AddInstance($relationship)
RaiseEvent 0 10040 "Discovered relationship: BMC Windows computer contains smash device on [$targetObjectId]"
}
else
{
RaiseEvent 0 10041 "Discovered no relationship: BMC Windows computer contains smash device on [$targetObjectId]"
}

$discoveryData

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>targetObjectId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>smBiosGuid</Name>
<Value>$Target/Property[Type="Microsoft.SystemCenter.OOB.SMASHDevice"]/SMBIOSGuid$</Value>
</Parameter>
<Parameter>
<Name>discovery</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>smashIP</Name>
<Value>$Target/Property[Type="Microsoft.SystemCenter.OOB.WSManDevice"]/IP$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>600</TimeoutSeconds>
</DataSource>
</Discovery>