Hi,I am in the process of extending scom computer objects with data from an external portal. This portal has inventory, CMDB, finacial data etc and is developed in house.
Typically, all windows computer object should have a property saying if the server has backup responsibility, the customer name etc. I can access all this data from a webAPI with powershell Invoke-RestMethod. URL looks something like this
http://cmdb/api/server?ID=netBiosNameHow would you add this in to scom. Should i create a script stick it in an orchestrator runbook and add the data directly, or could i run it as a timedPowershellDiscovery on every agent?
Can any of you think of a reason why my script work out of the management pack but not when running in the workflow? I have some logging done so i can see the API status code in Opsmgr event log, but the entry is just blank. If i run the script directly in PowerShell. everything Works.
This is how my XML looks now.
<?xml version="1.0" encoding="utf-8"?> <Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="C:\Users\aa98\AppData\Local\Temp\tmp38DA.tmp"> <IntervalSeconds>600</IntervalSeconds> <SyncTime>22:59</SyncTime> <ScriptName>SCOM-CMDB-Discovery.ps1</ScriptName> <ScriptBody> param([string]$sourceId, [string]$managedEntityId, $apiURL, [string]$FQDN) #Connect to SCOM locally, Import-Module OperationsManager New-SCOMManagementGroupConnection -ComputerName 'localhost' $apiuser = "domain\user" $apipassword = ConvertTo-SecureString "password" -AsPlainText -Force $apicred = New-Object System.Management.Automation.PSCredential ($apiuser,$apipassword) #Get a list of the computers that are active in SCOM $ComputerClass = Get-SCOMClass -Name 'Microsoft.Windows.Computer' $SCOMComputerList = Get-SCOMClassInstance -Class $ComputerClass | % {$_.DisplayName} #Just to add a statuscode to our log $APIStatusCode = (Invoke-WebRequest -Uri $apiURL -Credential ($apicred)).StatusCode #Get the Incomming data to Include into SCOM $CMDBComputers = Invoke-RestMethod -Uri $apiURL -Credential ($apicred) #Create the API Object $api = new-object -comObject 'MOM.ScriptAPI' $discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId) #Log our Start $api.LogScriptEvent("IntilityCMDB.ROTServer", 1001, 4, $("API Connection Status: $APIStatusCode | Begin discovery of ROT CMDB Servers from: $apiURL - # of computers {0}" -f $CMDBComputers.count)) $ct = 0 foreach ($c in $CMDBComputers) { if ($SCOMComputerList.contains($c.Name+$FQDN)) { #This server is both in SCOM and our CMDB, we will add it to the objects $ct++ $instanceCMDB = $discoveryData.CreateClassInstance("$MPElement[Name='CMDB.ROTServer']$") $instanceCMDB.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $c.Name+$FQDN) $instanceCMDB.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "ROT Computer") $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTRole$", $c.Role) $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTEnvironment$", $c.Environment) $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTBackup$", $c.BackupResponsibility) $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTManaged$",$c.OperatingResponsibility) $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTCompany$", $c.Location.Name) $instanceCMDB.AddProperty("$MPElement[Name='CMDB.ROTServer']/ROTvCenterHost$", $c.ESX.Name) $discoveryData.AddInstance($instanceCMDB) } } $api.LogScriptEvent("CMDB.ROTServer", 1001, 4, $("Completed discovery - Servers matching CMDB: {0}" -f $ct)) # Proper way to return discovery data in powershell $discoveryData </ScriptBody> <Parameters> <Parameter> <Name>sourceID</Name> <Value>$MPElement$</Value> </Parameter> <Parameter> <Name>managedEntityID</Name> <Value>$Target/Id$</Value> </Parameter> <Parameter> <Name>apiURL</Name> <Value>https://cmdb/api/server?orderBy=Name&start=0&top=9999</Value> </Parameter> <Parameter> <Name>FQDN</Name> <Value>domain</Value> </Parameter> </Parameters> <TimeoutSeconds>600</TimeoutSeconds> </Configuration>