Procedure to compare vCenter alarm definitions with PowerCLI
search cancel

Procedure to compare vCenter alarm definitions with PowerCLI

book

Article ID: 412660

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

In some environments, administrators may need to verify whether two vCenter Servers have identical alarm definitions. This is useful during migration, consolidation, or validation tasks, as inconsistencies in alarms may lead to unexpected monitoring gaps.
This article provides a PowerCLI script that connects to two vCenter Servers, extracts all alarm definitions, and compares them to highlight any differences.

Environment

  • VMware vCenter Server (any supported version)
  • PowerCLI installed on a management workstation
  • Administrative credentials for both vCenter servers

Resolution

Use the provided PowerCLI script to connect to two vCenter Servers, retrieve their alarm definitions, and compare them. The output will display which alarms exist only in VC1 and which exist only in VC2.

# Note:
# 1. Replace $VC1, $VC2, $VC1_USER, $VC2_USER, $VC1_PASSWORD, $VC2_PASSWORD with actual vCenter information.
# 2. The script will disconnect any existing vCenter sessions before connecting to the specified servers.
# 3. The results will be displayed in the console, indicating alarms unique to each vCenter.

$VC1 = "FQDN or IP of vCenter 1"
$VC1_USER = "[email protected]"
$VC1_PASSWORD = "administrative credential of vCenter 1"

$VC2 = "FQDN or IP of vCenter 2"
$VC2_USER = "[email protected]"
$VC2_PASSWORD = "administrative credential of vCenter 2"

function Get-AlarmKey {
  param($alarm)
  $info = $alarm.ExtensionData.Info
  if ($info.SystemName) { return "SYSTEM::$($info.SystemName)" }
  elseif (-not [string]::IsNullOrWhiteSpace($alarm.Name)) { return "CUSTOM::$($alarm.Name)" }
  else { return "ID::$($alarm.ExtensionData.MoRef.Value)" } # fallback to ID
}

# Disconnect existing connections, if any
if ($global:DefaultVIServers -and $global:DefaultVIServers.Count -gt 0) {
    Disconnect-VIServer -Server * -Force -Confirm:$false
}

# Collect alarm definitions from VC1
Connect-VIServer -server $VC1 -user $VC1_USER -password $VC1_PASSWORD
$a = Get-AlarmDefinition
Disconnect-VIServer -Confirm:$false

# Collect alarm definitions from VC2
Connect-VIServer -server $VC2 -user $VC2_USER -password $VC2_PASSWORD
$b = Get-AlarmDefinition
Disconnect-VIServer -Confirm:$false

# Build comparable keys
$keysA = $a | ForEach-Object { Get-AlarmKey $_ }
$keysB = $b | ForEach-Object { Get-AlarmKey $_ }

# Compare
$onlyInA = Compare-Object $keysA $keysB -PassThru | Where-Object { $_.SideIndicator -eq '<=' }
$onlyInB = Compare-Object $keysA $keysB -PassThru | Where-Object { $_.SideIndicator -eq '=>' }

# Output results
$onlyInA | Sort-Object | ForEach-Object { "Only in VC ${VC1}: $_" }
$onlyInB | Sort-Object | ForEach-Object { "Only in VC ${VC2}: $_" }

 

Example Output

When running the script, the console may display results similar to the following:

Only in VC XXX: SYSTEM::alarm.AlarmSystem.hostConnectionAndPowerState
Only in VC XXX: CUSTOM::NTP is stopped
Only in VC OOO: CUSTOM::Snapshot delete failed
Only in VC OOO: CUSTOM::High CPU usage
Only in VC OOO: CUSTOM::High memory usage
 
  • SYSTEM::... indicates a built-in system alarm that comes with vCenter.

  • CUSTOM::... indicates a user-created alarm.

 

 

Additional Information

Limitations / Known Issues

  • The script compares only the presence of alarms (based on system name, custom name, or managed object reference ID).

  • It does not compare the internal alarm configuration or conditions (for example, expressions, triggers, or actions).

  • If two alarms have the same name but different conditions, they will appear as identical in this comparison.