Automatically Remove SCOM Agents that have not sent a Heartbeat in “X” Days

Many customers that use SCOM have several hundred to thousands or even more agents that are monitored. In many environments it is a different team that images new servers than the team that manages SCOM. It is sometimes the case that the servers that are decommissioned are not often removed from SCOM and thus you will see a heartbeat alert. This can make it a pain to get the computer names from the heartbeat alert and then remove them from SCOM.

Kevin Holman has a blog (here) on this to remove large amounts of SCOM agents from a text file and the 4th activity of this runbook uses his script. But what if you want to pull these names automatically from the SCOM heartbeat alert into a file based on a set number of days (30) where a system has not sent a heartbeat? Through the help of Orchestrator and PowerShell we can do that.

What the runbook will look like:

  1. Schedule – This first step I have set to run every day at 5:00pm. If you choose to, set a time as to how often you would like the runbook to run.
  2. Create Heartbeat Folder – This is creating the file that will be used to store the server names that return with a heartbeat failure.
    1. New-Item -Path ‘\\Servername\Folderpath\heartbeatfailures.txt’
  3. Get Heartbeat – In this Activity, we set the Age of the alert in days “30” save it to the file specified above.
    1. You will need to change the variable in the script. You do not need a variable. And can hardcode the name if you choose.

  4. Remove SCOM Agents – Here the runbook is using Kevin’s script and make sure to specify the file name and path. He has a place holder for this already.

Time to test.

For testing purposes only, I chose 1 day for my heartbeat failure limit.

Once that threshold is reached, and the runbook runs on its schedule, the agents should be removed from SCOM.

Agent removal verification.

Download the runbook here. I have also included my scripts on GitHub. Kevin’s script can be copied from the link to his article above.

*** Note ***


Please go through the scripts as necessary and adjust to your requirements. Make note of the file path and verify they align in all the scripts.

THE SOFTWARE IS PROVIDED “AS IS”, AND WITHOUT WARRANTY OF ANY KIND.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s