Copy Alarms from one vCenter to Another.


This is something I have been wanting to do for a while, but only recently where I actually had a need to complete it.
At the core I wanted to be able to copy vcenter alarms from one vcenter to another. Currently there isn’t really a great way to do that, so I am hoping this script can fill a void for some people.

I used a very small portion of Lucd’s Move-Alarm function, which if you are interested in Alarms and Powercli, or just PowerCLI in general, go check out his blog.

Alright so lets get into it, here is the core of the script

param($alarmname,$oldserver, $newserver, $newfolder="Datacenters")

Set-Variable -Name alarmLength -Value 80 -Option "constant" -erroraction silentlycontinue
disconnect-viserver * -confirm:$false
connect-viserver $oldserver, $newserver -erroraction silentlycontinue

$alarms=Get-AlarmDefinition $alarmname | ?{$_.uid -like "*$oldserver*"}

$to=Get-Folder $newfolder | ?{$_.uid -like "*$newserver*"}|get-view

 $alarmview = Get-View $Alarms

 disconnect-viserver $oldserver -confirm:$false

 $alarmMgr = Get-View AlarmManager

ForEach($alarm in $alarmview)

 $newAlarm = New-Object VMware.Vim.AlarmSpec
 $newAlarm = $alarm.Info


Here is how it looks in action….


Sorry for the blocking out stuff :(.

So we see in the example above that we are choosing which alarms are copied by their name. In this example I grabbed and copied all the alarms that start with either Conrad, or vNoob.  In this case there only happened to be one of each, but you get the point :).

If you wanted to combine this with my last post you could copy all the alarms that have been created by users…

$myalarms=get-alarmdefinition | Where-Object {[INT]$“-”)[2] -gt 99}  | select-object -expandproperty name

Transfer-Alarm -alarmname $myalarms -olderserver “oldvcenter.vnoob.local” -newserver “newvcenter.vnoob.local”

Oh so much fun to be had with alarms. Hope you enjoy it!

1.9 KiB

4 Responses to Copy Alarms from one vCenter to Another.

  1. Hi,

    The script is not working, do you have any clue ?

    Exception lors de l’appel de « CreateAlarm » avec « 2 » argument(s) : « 
    Required parameter entity is missing
    while parsing call information for method CreateAlarm
    at line 1, column 218
    while parsing SOAP body
    at line 1, column 207
    while parsing SOAP envelope
    at line 1, column 38
    while parsing HTTP request for method create
    on object of type vim.alarm.AlarmManager
    at line 1, column 0 »
    Au niveau de H:\migration-vcenter\copy-alarm-vmnoob.ps1 : 24 Caractère : 22
    + $alarmMgr.CreateAlarm <<<< ($to.MoRef,$newAlarm)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    • One of the first lines in the error says that you are missing a required parameter. Are you sure you have values for the 3 parameters?

Leave a Reply