Discovery of Operations Manager deployment

Microsoft.SystemCenter.OM.Products.Discovery (Discovery)

This discovers the Operations Manager deployed versions.

Element properties:

TargetMicrosoft.SystemCenter.HealthService
EnabledTrue
Frequency86400
RemotableFalse

Member Modules:

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

Source Code:

<Discovery ID="Microsoft.SystemCenter.OM.Products.Discovery" Target="SCLibrary!Microsoft.SystemCenter.HealthService" Enabled="true" ConfirmDelivery="false" Remotable="false" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes/>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>86400</IntervalSeconds>
<SyncTime/>
<ScriptName>SCOMInstalledProducts</ScriptName>
<ScriptBody><Script>
param($IsRHS)
$IsRHS = [boolean]::Parse($IsRHS)
$products = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, InstallDate, PSChildName | Where-Object {$_.DisplayName -like '*Operations Manager*' -or $_.DisplayName -eq 'Microsoft Monitoring Agent'}
# Create a new discovery data packet
$oAPI = new-object -comObject "MOM.ScriptAPI"
$oDisc = $oAPI.CreateDiscoveryData(0, "$MPElement$", "$Target/Id$")
$oDisc.IsSnapshot = $True
foreach($OMproduct in $products)
{
if(-not $OMproduct.PSChildName.startswith("{"))
{
continue;
}
$productComponentID = $OMproduct.PSChildName
$installer = new-object -comobject "WindowsInstaller.Installer"
$productList = @($installer.GetType().InvokeMember("ProductsEx", "GetProperty", $null, $installer,('', '', 4)))
$patchListString = ""
$InstallDate = ""
$KBNumber = ""
foreach($product in $productList)
{
$ProductCode=$product.GetType().InvokeMember("ProductCode", "GetProperty", $null, $product, 1)
if($ProductCode -eq $productComponentID)
{
$patchList=$installer.GetType().InvokeMember("PatchesEx", "GetProperty", $null, $installer,($ProductCode, "", 7, 1))
foreach($patch in $patchList)
{
$patchListString = $patch.GetType().InvokeMember("PatchProperty", [System.Reflection.BindingFlags]::GetProperty, $Null, $patch, "DisplayName")
$InstallDate = $patch.GetType().InvokeMember("PatchProperty", [System.Reflection.BindingFlags]::GetProperty, $Null, $patch, "InstallDate")
$PackageName = $patch.GetType().InvokeMember("SourceListInfo", [System.Reflection.BindingFlags]::GetProperty, $Null, $patch, "PackageName")
$PackageName = $PackageName.Split("-")
$KBNumber = $PackageName[0]
}
}
}
if($patchListString -ne $null -and $patchListString -ne "")
{
$patchListString = $patchListString.Substring($patchListString.IndexOf("Manager") + 8)
}
if($InstallDate -ne $null -and $InstallDate -ne "")
{
$InstallDate = [datetime]::ParseExact($InstallDate,&#x201D;yyyyMMdd&#x201D;,$null).toshortdatestring()
}else{
$InstallDate = [datetime]::ParseExact($OMproduct.InstallDate,&#x201D;yyyyMMdd&#x201D;,$null).toshortdatestring()
}
switch -wildcard ($OMproduct.DisplayName)
{
"*Agent" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.Agent']$"); break }
"*Reporting*" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.Reporting']$"); break }
"*Audit Collection Server*" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.ACS']$"); break }
"*Server" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.OM']$"); break }
"*Web Console" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.WebConsole']$"); break }
"*Console" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.Console']$"); break }
"*Gateway" { $oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts.Gateway']$") }
}
$oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", "$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$")
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/ProductDisplayName$", $OMproduct.DisplayName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/Domain$", "$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/DomainDnsName$")
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/ComputerName$", "$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$")
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/PatchInstalled$", $patchListString)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/InstallDate$", $InstallDate)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/Version$", $OMproduct.DisplayVersion)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.OMProducts']/KBNumber$", $KBNumber)
$oDisc.AddInstance($oInst1)
}
if($IsRHS)
{
$SCOMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$SCOMModulePath = Join-Path (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory &#x201C;OperationsManager&#x201D;
Import-module $SCOMModulePath
$DBInfo = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\" | Select-Object DatabaseServerName, DataWarehouseDBServerName, DatabaseName, DataWarehouseDBName

#Database Discovery
$computerName = [System.Net.Dns]::GetHostEntry($DBInfo.DatabaseServerName.Split('\')[0]).HostName
$dbVersion = Get-SCOMOperationsDatabase
$oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']$");
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/InstanceName$", $DBInfo.DatabaseServerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/ProductDisplayName$", "Operations Manager Database")
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/DatabaseName$", $DBInfo.DatabaseName)
$oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/ComputerName$", $computerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/Version$", $dbVersion)
$oDisc.AddInstance($oInst1)

#Data Warehouse Discovery
$computerName = [System.Net.Dns]::GetHostEntry($DBInfo.DataWarehouseDBServerName.Split('\')[0]).HostName
$params = New-Object Microsoft.EnterpriseManagement.Warehouse.StoredProcedureParameterCollection
$dwVersion = $($($(Get-SCOMManagementGroup).GetDataWarehouse()).GetDataWarehouseData("sdk.p_GetDatawarehouseVersion", $params)).Results[0].Values[0]
$oInst1 = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']$");
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/InstanceName$", $DBInfo.DataWarehouseDBServerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/ProductDisplayName$", "Operations Manager Data Warehouse")
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/DatabaseName$", $DBInfo.DataWarehouseDBName)
$oInst1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/ComputerName$", $computerName)
$oInst1.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Installed.Database']/Version$", $dwVersion)
$oDisc.AddInstance($oInst1)
}
$oDisc
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>IsRHS</Name>
<Value>$Target/Property[Type="SCLibrary!Microsoft.SystemCenter.HealthService"]/IsRHS$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>900</TimeoutSeconds>
</DataSource>
</Discovery>