Hi Any idea why I am getting the errors?
if($deleteOriginal){
$alarmObj.RemoveAlarm()
}
else{
$updateAlarm = New-Object VMware.Vim.AlarmSpec
$updateAlarm = $alarmObj.Info
$oldName = $alarmObj.Info.Name
$oldState = $alarmObj.Info.Enabled
$oldDescription = $alarmObj.Info.Description
$suffix = " (moved to " + ([string]($to | %{$_.Name + ","})).TrimEnd(",") + ")"
if(($oldName.Length + $suffix.Length) -gt $alarmLength){
$newName = $oldName.Substring(0, $alarmLength - $suffix.Length) + $suffix
}
else{
$newName = $oldName + $suffix
}
$updateAlarm.Name = $newName
$updateAlarm.Enabled = $false
$updateAlarm.Description += ("`r`n Original name: " + $oldName)
$updateAlarm.Expression.Expression | %{
if($_.GetType().Name -eq "EventAlarmExpression"){
$_.Status = $null
$needsChange = $true
}
}
$alarmObj.ReconfigureAlarm($updateAlarm)
$alarmObj.Info.Name = $oldName
$alarmObj.Info.Enabled = $oldState
$alarmObj.Info.Description = $oldDescription
}
$newAlarm = New-Object VMware.Vim.AlarmSpec
$newAlarm = $alarmObj.Info
$oldName = $alarmObj.Info.Name
$oldDescription = $alarmObj.Info.Description
foreach($destination in $To){
if($To.Count -gt 1){
$suffix = " (" + $destination.Name + ")"
if(($oldName.Length + $suffix.Length) -gt $alarmLength){
$newName = $oldName.Substring(0, $alarmLength - $suffix.Length) + $suffix
}
else{
$newName = $oldName + $suffix
}
$newAlarm.Name = $newName
$newAlarm.Description += ("`r`n Original name: " + $oldName)
}
$newAlarm.Expression.Expression | %{
if($_.GetType().Name -eq "EventAlarmExpression"){
$_.Status = $null
$needsChange = $true
}
}
$alarmMgr.CreateAlarm($destination.MoRef,$newAlarm)