Importing alarms from one vCenter Server to another using a PowerCLI script fails.
The issue occurs only for alarms that reference performance metrics.
VMware vCenter Server 8.x
VMware PowerCLI 13.x
During the alarm import process, the XML file contains a CounterId value that is specific to the source vCenter. If this CounterId does not match the corresponding CounterId in the destination vCenter, the import operation fails and the alarm cannot be created successfully.
The exported alarm XML file contains a CounterId that is specific to the source vCenter Server. If the CounterId referenced in the XML does not exist or does not match the corresponding metric CounterId in the destination vCenter Server, the alarm import operation fails.
CounterIds are not guaranteed to be identical across different vCenter environments, even when they monitor the same performance metric.
Modify the CounterId in the alarm XML file to match the correct CounterId in the destination vCenter Server before importing the alarm.
Identify the correct CounterId for the required performance metric in the destination vCenter Server.
Open the exported alarm XML file in a text editor.
Locate the <CounterId> entry used by the alarm definition.
Replace the existing CounterId with the CounterId from the destination vCenter.
Save the XML file.
Re-run the PowerCLI script to import the alarm.
After updating the CounterId, the alarm should import successfully into the destination vCenter Server.
Note: Please find the attached PowerCLI sample script to Export and Import Alarms.
It is recommended to validate CounterIds when migrating alarms across vCenter Servers.
# Using below script we can validate CounterIds across vCenter Servers.
Connect-VIServer -Server "vc-ip" -user "user" -password "password"
$perfMgr = Get-View (Get-View ServiceInstance).Content.PerfManager
# Fetch the lable based on the CounterId.
$perfMgr.PerfCounter |
Where-Object {
$_.key -eq "CounterId" # CounterId needs to be changed.
} |
Select Key, @{N="Label";E={$_.NameInfo.Label}}
# Fetch the CounterId based on the lable.
$perfMgr.PerfCounter |
Where-Object {
$_.NameInfo.label -eq "Lable" # Lable needs to be changed.
} |
Select Key, @{N="Label";E={$_.NameInfo.Label}}