Remove Data from the SCOM Database Instantly - The PowerShell Way!

Posted by : on

powershell   operationsManager   troubleshooting   projects

:book: Introduction

I have had many cases where I’ve had to run the following SQL Queries by Kevin Holman: Deleting and Purging data from the SCOM Database (kevinholman.com) (A big thank you to Kevin Holman for his guide!)

After the 6th or 7th time running the tsql queries I decided that I should automate this process in Powershell, and make it very easy to do this automatically for as many servers as needed. This script will query the Operations Manager database and run all the steps in Kevin Holman’s queries. The script will ask questions at each step to verify the action is correct. You have to answer Y or N before the script will proceed.

:exclamation: Important!

It is recommended to only run the script when requested by a Microsoft Support Engineer. This script can be dangerous if used incorrectly.
 
If you absolutely need to run the script, make sure you have full backups of your SCOM SQL Instances / Databases!

:arrow_down: How to get it

You can get a copy of the script here:
Remove-SCOMBaseManagedEntity.ps1 :arrow_left: Direct Download Link
or
Personal File Server - Remove-SCOMBaseManagedEntity.ps1 :arrow_left: Alternative Download Link
or
Personal File Server - Remove-SCOMBaseManagedEntity.txt :arrow_left: Text Format Alternative Download Link

:notebook: Note

You may edit line 769 in the script to change what happens when the script is run without any arguments or parameters, this also allows you to change what happens when the script is run from the Powershell ISE.

 

:classical_building: Argument List

Parameter Alias ValueFromPipeline Type Description
AssumeYes yes   Switch Optionally assume yes to any question asked by this script.
Database     String The name of the OperationsManager Database for SCOM.
DontStop ds   Switch Optionally force the script to not stop when an error occurs connecting to the Management Server.
Id     Array You may provide any Base Managed Entity Id’s to be deleted specifically from the Operations Manager Database.
InputFile     String A file you would like to have the script input as a list of Agents. The file should have a new line for each server.
ManagementServer ms   String SCOM Management Server that we will remotely connect to. If running on a Management Server, there is no need to provide this parameter.
Name     Array The Base Managed Entity Display Name of the object you are wanting to delete from the Operations Manager Database.
Servers   True Array Each Server (comma separated) you want to Remove related BME ID’s related to the Display Name in the OperationsManager Database. This will also remove from Agent Managed.
SqlServer     String SQL Server/Instance, Port that hosts OperationsManager Database for SCOM.

:page_with_curl: How to use it

Example 1

Remove SCOM BME Related Data from the OperationsManager DB, for Agent1 in the Management Group:

Get-SCOMAgent -Name Agent1.contoso.com | %{.\Remove-SCOMBaseManagedEntity.ps1 -Servers $_.DisplayName}

Example 2

Remove SCOM BME Related Data for 2 Agent machines:

.\Remove-SCOMBaseManagedEntity.ps1 -Servers IIS-Server.contoso.com, WindowsServer.contoso.com

Example 3

Remove SCOM BME Related Data for 2 Agent machines automatically with no prompts / questions:

.\Remove-SCOMBaseManagedEntity.ps1 -Servers IIS-Server.contoso.com, WindowsServer.contoso.com -AssumeYes

Example 4

Remove SCOM BME IDs from the Operations Manager Database:

.\Remove-SCOMBaseManagedEntity.ps1 -Id C1E9B41B-0A35-C069-16EB-00AC43BB9C47, CB29ECDE-BCE8-2213-D5DD-0353116EDA6B

Example 5

If you need to input a file that contains Agents (CSV or TXT):

.\Remove-SCOMBaseManagedEntity.ps1 -InputFile C:\Temp\List_Of_Servers.txt

Leave some feedback if this helped you! :v:

Page Views


Share on:
About Blake Drumm
Blake Drumm

I like to collaborate and work on projects. My skills with Powershell allow me to quickly develop automated solutions to suit my customers, and my own needs.

Email :

Website :

About Blake Drumm

My name is Blake Drumm, I am working on the Azure Monitoring Enterprise Team with Microsoft. Currently working to update public documentation for System Center products and write troubleshooting guides to assist with fixing issues that may arise while using the products. I like to blog on Operations Manager and Azure Automation products, keep checking back for new posts. My goal is to post atleast once a month if possible.

Follow @blakedrumm
Useful Links