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!

[wpfilebase tag=file id=10 /]


marc crawford · February 20, 2014 at 1:18 pm

Wow, great script! Wish I would have seen this about 6 months ago …

    C-Rad · February 20, 2014 at 1:20 pm

    Fortunately it has been here for 11 months 😛

    And it is in my new scripts section! So check that out too!

tntteam · March 27, 2015 at 3:57 am


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

    C-Rad · March 27, 2015 at 9:19 am

    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