Computers deleted - associated with custom script discovery

Hi guys,

Common problem is that you have orphaned computer Objects in Windows server view. Usually these get removed automaticly after some time. But now i have Objects still Associated With a custom discovery written With PowerShell. and i Wonder if there is something i need to do With the actual script for this?

Basicly the script compares Objects in scom With Objects in Our cmdb and then adds exteded property to a New class based on Windows computer. Here’s a snippet of it.


$ct = 0
    foreach ($c in $CMDBComputers) {

    if ($SCOMComputerList.contains($c.Name+$FQDN)) {
    #This server is both in SCOM and our CMDB. Starts by adding regular server properties from ROT

    $instanceCMDB = $discoveryData.CreateClassInstance("$MPElement[Name='ROTServer']$")
    $instanceCMDB.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $c.Name+$FQDN)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTRole$", $c.Role)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTType$", $c.Type)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTEnvironment$", $c.Environment)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTBackup$", $c.BackupResponsibility)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTCompany$", $c.CompanyName)
    $instanceCMDB.AddProperty("$MPElement[Name='ROTServer']/ROTvCenterHost$", $c.ESXName)
1 Like

Hi Jelly. this is a little different but thank you for Your suggestion :slight_smile:

Koen, is it so that i have to base my class of the healtservice class or just use it as a check? Now i get all computers in scom from the Windows computer class

    $ComputerClass = Get-SCOMClass -Name 'Microsoft.Windows.Computer'
    $SCOMComputerList = Get-SCOMClassInstance -Class $ComputerClass | % {$_.DisplayName}

Hi Ehrnst,

do you have any solution for this problem now?

I have the same problem now …

Danger Will Robinson!

Now that I’ve your attention with the above I’d like to note that the below should only be used if you know what you’re doing and are sure item can be removed.

I use the below code to cleanup a similar issue we have with an automated network discovery system that ties into our CMDB. The code will take a SCOM instance and indicate to the management server that the instance is no longer needed and should be removed. There are no warning prompts and not much documentation on the below process.


#Get the instance you want to remove from SCOM
$InstanceToRemove = Get-SCOMClassInstance -Id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

#Choose the connector that will make this change, We used network as it is related to our issue
$NetworkConnector = Get-SCOMConnector | where {$ -like "Network Monitoring Internal Connector"}

#Create a new Incremental Discovery Data object (You may need to load Microsoft.EnterpriseManagement.OperationsManager.dll)
$IncrementalDiscoveryData = new-object Microsoft.EnterpriseManagement.ConnectorFramework.IncrementalMonitoringDiscoveryData

#Submit the item to the discovery data as a removal, casting isn't required

#Tell the engine to Commit this new discovery data
1 Like


This is a common problem.
One solution for it is to get the healthservices from SCOM. (Get-SCOMClass -DisplayName “Health Service”| Get-SCOMClassInstance)
And only set the properties if the object still has a healthservice.
The objects which are not touched and don’t have a health service anymore for a while will be removed from SCOM.

Thank you for Your reply. So you would suggest doing the match on healht service instead of Windows computer class?

I’m not sure this will work as the discovery has not been disabled via an override (to my knowledge) so I’ve post as a comment. I recommend reading up on this PowerShell command as it can be pretty intensive on the databases.


Hi, as suggested I changed to check if the health service still exists. Seems to work!

like this
$ComputerClass = Get-SCOMClass -Name ‘Microsoft.SystemCenter.HealthService’
$SCOMComputerList = Get-SCOMClassInstance -Class $ComputerClass | % {$_.DisplayName}