OpsMgr 2012 – how to delete an old product connector


 

In OpsMgr 2007R2 – we issued a KB article on how to remove an old unwanted product connector:

 

http://support.microsoft.com/kb/2626670

 

To use this same script in OpsMgr 2012 – I made some changes – you can copy and paste the script below into a text file, then name it “DeleteConnector.ps1”

——————————

 

param(
    [String] $connectorName,
    [String] $mgName="localhost"
)
$mg = new-object Microsoft.EnterpriseManagement.ManagementGroup $mgName
$admin = $mg.GetConnectorFrameworkAdministration()
##########################################################################################
# Configures a connector with the specified name.
##########################################################################################
function New-Connector([String] $name)
{
    $connectorForTest = $null;
    foreach($connector in $admin.GetMonitoringConnectors())
    {
     if($connector.Name -eq ${name})
     {
      $connectorForTest = Get-SCOMConnector -id $connector.id
     }
    }
    if ($connectorForTest -eq $null)
    {
        $testConnector = New-Object Microsoft.EnterpriseManagement.ConnectorFramework.ConnectorInfo
        $testConnector.Name = $name
        $testConnector.Description = "${name} Description"
        $testConnector.DiscoveryDataIsManaged = $false
        $connectorForTest = $admin.Setup($testConnector)
        $connectorForTest.Initialize();
    }
    return $connectorForTest
}
##########################################################################################
# Removes a connector with the specified name.
##########################################################################################
function Remove-Connector([String] $name)
{
    $testConnector = $null
    foreach($connector in $admin.GetMonitoringConnectors())
    {
     if($connector.Name -eq ${name})
     {
      $testConnector = Get-SCOMConnector -id $connector.id
     }
    }
    if ($testConnector -ne $null)
    {
    if($testConnector.Initialized)
    {
    foreach($alert in $testConnector.GetMonitoringAlerts())
    {
     $alert.ConnectorId = $null;
     $alert.Update("Delete Connector");
    }
    $testConnector.Uninitialize()
    }
    $connectorIdForTest = $admin.Cleanup($testConnector)
    }
}
##########################################################################################
# Delete a connector’s Subscription
##########################################################################################
function Delete-Subscription([String] $name)
{
foreach($testconnector in $admin.GetMonitoringConnectors())
{
   if($testconnector.Name -eq $name)
   {
     $connector = Get-Connector -id $testconnector.id
   }
}
$subs = $admin.GetConnectorSubscriptions()
foreach($sub in $subs)
{
  if($sub.MonitoringConnectorId -eq $connector.id)
  {
   $admin.DeleteConnectorSubscription($admin.GetConnectorSubscription($sub.Id))
  }
}
}
#New-Connector $connectorName
write-host "Delete-Subscription"
Delete-Subscription $connectorName
write-host "Remove-Connector"
Remove-Connector $connectorName

 

———————————


Comments (2)

  1. HendrikWiese says:

    Hi,

    Should one change the [String] $connectorName to [String] $connectorName = "Alert Sync: Connector Name"?

    Regards,

    HendrikWiese

  2. Hentman says:

    The line " $connector = Get-Connector -id $testconnector.id "

    should be changed into

    $connector = Get-SCOMConnector -id $testconnector.id

    to be used with SCOM 2012 SP1

    Kind Regards