Kevin Holman's System Center Blog

Posts in this blog are provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified in the Terms of UseAre you interested in having a dedicated engineer that will be your Mic

OpsMgr 2012 – how to delete an old product connector

OpsMgr 2012 – how to delete an old product connector

  • Comments 2
  • Likes

 

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
  • Hi,

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

    Regards,

    HendrikWiese

  • 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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
Search Blogs