大网数据广告活动
启动与系统组件

Remove old product connectors from Operations Manager

· 52CE 我爱测

Describes how to remove an old product connector from System Center - Operations Manager by using a PowerShell script.

Summary

This article describes how to remove an old product connector from Microsoft System Center - Operations Manager by using the OperationsManager PowerShell module and the sample script in this article.

Original product version:   System Center Operations Manager
Original KB number:   2626670

When to use this procedure

Use this procedure only if a product connector is no longer required in the management group and must be removed from the environment. Because connector removal affects connector-related configuration and data associations, this procedure should be treated as a maintenance operation.

What this procedure does

The script identifies the specified connector, removes any connector subscriptions that reference it, clears connector associations from related alerts when applicable, uninitializes the connector if required, and then removes the connector from the management group.

Prerequisites

Before running this procedure:

  • Verify that the specified connector isn't an internal Operations Manager connector.
  • Back up both the operational and data warehouse databases before making any changes.
  • Run the procedure only from a management server or PowerShell session that has the required Operations Manager components available.
  • Verify the exact connector name before removal. If possible, first validate the target connector in a non-production or low-risk scenario before you run the deletion in production.
  • Don't modify or improvise the script to work around startup or runtime errors. Use only the published, validated version of the script.

PowerShell script

Use the following PowerShell script to remove the specified product connector only after completing the prerequisites.

Important: Don't attempt to work around errors in earlier versions of this script by manually removing invalid startup references or changing individual lines without validating the full procedure. In terms of testing, an ad hoc workaround can leave the environment in an inconsistent state and may require database restoration to recover.

[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
param(
    [Parameter(Mandatory = $true)]
    [string]$ConnectorName,

[string]$ManagementServerName = 'localhost',

    [switch]$AllowWildcard
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function Get-MatchingConnector {
    param(
        [Parameter(Mandatory = $true)]
        [object[]]$Connectors,

        [Parameter(Mandatory = $true)]
        [string]$Name,

        [switch]$Wildcard
    )

    if ($Wildcard) {
        @($Connectors | Where-Object { $_.Name -like $Name })

    else {
        @($Connectors | Where-Object { $_.Name -eq $Name })
}

}

function Remove-ConnectorSubscriptions {
    param(
        [Parameter(Mandatory = $true)]
        $Admin,

        [Parameter(Mandatory = $true)]
        [object[]]$Connectors
    )

    $connectorIds = @($Connectors | ForEach-Object { $_.Id })

    $subscriptions = @(
        $Admin.GetConnectorSubscriptions() |
        Where-Object { $connectorIds -contains $_.MonitoringConnectorId }
    )

    foreach ($subscription in $subscriptions) {
        $target = "{0} [{1}]" -f $subscription.DisplayName, $subscription.Id
        if ($PSCmdlet.ShouldProcess($target, 'Delete connector subscription')) {
            Write-Host "Deleting subscription: $($subscription.DisplayName)"
            $subObj = $Admin.GetConnectorSubscription($subscription.Id)
            $Admin.DeleteConnectorSubscription($subObj)
        }

}

function Remove-ConnectorObjects {
    param(
        [Parameter(Mandatory = $true)]
        $Admin,

        [Parameter(Mandatory = $true)]
        [object[]]$Connectors
    )

    foreach ($connector in @($Connectors)) {
        Write-Host "Processing connector: $($connector.Name) [$($connector.Id)]"

        if ($connector.Initialized) {
            $alerts = @($connector.GetMonitoringAlerts())

            if (@($alerts).Count -gt 0) {
                Write-Host "  Disconnecting $($alerts.Count) alert(s) from connector..."
            }

            foreach ($alert in @($alerts)) {
                $alertTarget = "{0} [{1}]" -f $alert.Name, $alert.Id
                if ($PSCmdlet.ShouldProcess($alertTarget, "Clear ConnectorId for '$($connector.Name)'")) {
                    $alert.ConnectorId = $null
                    $alert.Update("Delete Connector")
                }
            }

            if ($PSCmdlet.ShouldProcess($connector.Name, 'Uninitialize connector')) {
                Write-Host "  Uninitializing connector..."
                $connector.Uninitialize()
            }
        }

        if ($PSCmdlet.ShouldProcess($connector.Name, 'Delete connector')) {
            Write-Host "  Deleting connector..."
            [void]$Admin.Cleanup($connector)
        }
    }
}

New-DefaultManagementGroupConnection -ManagementServerName $ManagementServerName | Out-Null
$mg = Get-SCOMManagementGroup -ComputerName $ManagementServerName -ErrorAction Stop
$admin = $mg.GetConnectorFrameworkAdministration()

$allConnectors = @($admin.GetMonitoringConnectors())
$connectorsToDelete = @(Get-MatchingConnector -Connectors $allConnectors -Name $ConnectorName -Wildcard:$AllowWildcard)

if (@($connectorsToDelete).Count -eq 0) {
    throw "No connector found matching '$ConnectorName'."
 }

Write-Host "Matched connector(s):"
$connectorsToDelete | Select-Object Name, Id, Initialized | Format-Table -AutoSize
Write-Host ""

Remove-ConnectorSubscriptions -Admin $admin -Connectors $connectorsToDelete
Remove-ConnectorObjects -Admin $admin -Connectors $connectorsToDelete

Write-Host ""
Write-Host "Completed."

Run the script

Use the following syntax to run the script:

DeleteConnector.ps1 -ConnectorName <String> [-ManagementServerName <String>] [-AllowWildcard] [-WhatIf] [-Confirm]

Parameters

  • ConnectorName
    Specifies the connector name to remove. This parameter is required.

  • ManagementServerName
    Specifies the management server to connect to. This parameter is optional. The default value is localhost.

  • AllowWildcard
    Enables wildcard matching for the connector name. Use this parameter only when you intentionally want to match more than one connector.

Examples

Preview the operation without making changes:

.\DeleteConnector.ps1 -ConnectorName 'Old Connector Name' -ManagementServerName 'SCOMMS01' -WhatIf

Remove a connector by exact name:

.\DeleteConnector.ps1 -ConnectorName 'Old Connector Name' -ManagementServerName 'SCOMMS01'

Preview wildcard matching:

.\DeleteConnector.ps1 -ConnectorName 'OldConnector*' -ManagementServerName 'SCOMMS01' -AllowWildcard -WhatIf

Verify the result

After the script completes, verify the following:

  • The connector no longer appears in the connector list.
  • Any connector subscriptions associated with the connector were removed.
  • No alerts remain associated with the removed connector.
  • The Operations Manager console opens the connector view normally after the change.

Troubleshooting

  • If no connector is found, verify that the connector name is correct, and then rerun the script by using the exact connector name.

  • If you use wildcard matching, always run the script first by using -WhatIf to verify that only the intended connector is matched.

  • Don't use this procedure to remove internal Operations Manager connectors.

  • If a previous version of the script was used or modified ad hoc and the environment shows inconsistent behavior afterward, restore the OperationsManager databases from backup before retrying the procedure with the validated script version.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 04/15/2024
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。