Removing unwanted product connectors in SCOM 2012 R2 and SCOM 2016


 

image

 

There are certain management packs that will use product connectors to insert discovery data into SCOM, or to manage alerts.  Sometimes, you might find that the vendor did not provide a way to remove these product connectors, when you decide to stop using the MP or solution which created them.

Below is a PowerShell script that will allow you to remove them.  It supports inputting the product connector by name, or by a wildcard match using “*”.  The script will output all the matching connectors and allow you to choose to continue if you want them deleted.

***NEVER remove any product connector unless you are absolutely SURE of its origin and that it is one you want to delete.  It is a good idea to back up your databases before deleting connectors.

 

#=================================================== # # Delete a SCOM product connector in SCOM 2012 R2 and SCOM 2016 # # v1.0 # #=================================================== #=================================================== # Constants section - make changes here $connectorName = "foo.connector*" #This can be a full name or a partial name match with a wildcard (*) - so take great care here $servername="localhost" #=================================================== $mg = Get-SCOMManagementGroup -ComputerName $servername $admin = $mg.GetConnectorFrameworkAdministration() $connectors = $admin.GetMonitoringConnectors() $subs = $admin.GetConnectorSubscriptions() $ToBeDeletedNames = @() $ToBeDeletedList = $admin.GetMonitoringConnectors() | where {$_.Name -like "$connectorname"} FOREACH ($ToBeDeletedConn in $ToBeDeletedList) { [array]$ToBeDeletedNames += "`n" + $ToBeDeletedConn.Displayname } Write-Host "About to delete the following connectors: " $ToBeDeletedNames Write-Host "Press Y to continue, or any other key to stop" $response = Read-Host if ( $response -ne "Y" ) { Write-Host "Cancelling" exit } ########################################################################################## # Delete a connector’s Subscription ########################################################################################## function Delete-Subscription([String] $name) { foreach($testconnector in $connectors) { if($testconnector.Name -match $name) { $connector = Get-SCOMConnector -id $testconnector.id write-host "Found match on connector:" $connector.Displayname foreach($sub in $subs) { if($sub.MonitoringConnectorId -eq $connector.id) { write-host "Deleting subscription:" $sub.DisplayName "with ID" $sub.MonitoringConnectorId $admin.DeleteConnectorSubscription($admin.GetConnectorSubscription($sub.Id)) } } } } } ########################################################################################## # Removes a connector with the specified name. ########################################################################################## function Remove-Connector([String] $name) { $testConnector = $null foreach($connector in $connectors) { IF ($connector.Name -like $name) { $testConnector = Get-SCOMConnector -id $connector.id write-host "Found match on connector:" $connector.Displayname IF ($testConnector -ne $null) { IF ($testConnector.Initialized) { Write-Host "Found connector is initialized, disconnecting all alerts subscribe to the connector" FOREACH ($alert in $testConnector.GetMonitoringAlerts()) { $alert.ConnectorId = $null; $alert.Update("Delete Connector"); } Write-Host "Setting connector to UnInitialized" $testConnector.Uninitialize() } Write-Host "Deleting connector:" $testConnector.DisplayName "with ID" $testConnector.Id $connectorIdForTest = $admin.Cleanup($testConnector) } } } } write-host "Starting Delete-Subscription function" Delete-Subscription $connectorName write-host "Starting Remove-Connector function" Remove-Connector $connectorName

Comments (0)

Skip to main content