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)
On which vSphere version did you run this ? Was it 5.1 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
5.1 release 2
Do you really mean 5.1 Update 2 ?
I thought 5.1 Update 1 was the latest.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think this is the latest. I install it couple of weeks ago.
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.1 Release 2 build 1012425
---------------
Snapin Versions
---------------
VMWare AutoDeploy PowerCLI Component 5.1 build 768137
VMWare ImageBuilder PowerCLI Component 5.1 build 768137
VMware License PowerCLI Component 5.1 build 669840
VMware VDS PowerCLI Component 5.1 build 1012428
VMware vSphere PowerCLI Component 5.1 build 1012428
That is the PowerCLI release, I was asking about the vSphere/ESXi release you ran the script against.
Sorry for the confusion.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
vcenter 5.0.0 build 913577
Thanks. My script from Alarms – Moving them around, works in vSphere 5.*.
Just tested it, and the alarms were moved without any errors.
Could you show me how you call the script, in other words which parameters do you pass ?
Is the $to1, and $to2 if you use it, a valid blue folder ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference