tdubb123
Expert
Expert

vc alarms emaled settings

trying to get all vc alarms that are enabled with this but not getting the values

$results = @()
$alarmdefs = Get-AlarmDefinition -Server xxxxxxxxx | ? {$_.Enabled -eq "True"}
foreach ($alarm in $alarmdefs) {
$alarm_id = $alarm.id
$alarm_info = (get-view -id $alarm_id).info | ? {$_.Enabled -eq "True"}
$result = "" | select Name,Description,Enabled,Type,Operator,Red,Yellow
$result.Name = $alarm_info.Name
$result.Description = $alarm_info.Description
$result.Enabled = $alarm_info.Enabled
$result.Type = $alarm_info.Expression.Expression.Type
$result.Operator = $alarm_info.Expression.Expression.Operator
$result.Red = $alarm_info.Expression.Expression.Red
$result.Yellow = $alarm_info.Expression.Expression.Yellow
$results += $result
$results | export-csv -NoTypeinformation -Useculture alarms.csv
}
0 Kudos
1 Reply
LucD
Leadership
Leadership

The Export-Csv needs to be outside the foreach loop

$results = @()
$alarmdefs = Get-AlarmDefinition -Server vcsa7.local.lab | Where-Object { $_.Enabled -eq "True" }
foreach ($alarm in $alarmdefs) {
    $alarm_id = $alarm.id
    $alarm_info = (Get-View -Id $alarm_id).info | Where-Object { $_.Enabled -eq "True" }
    $result = "" | Select-Object Name, Description, Enabled, Type, Operator, Red, Yellow
    $result.Name = $alarm_info.Name
    $result.Description = $alarm_info.Description
    $result.Enabled = $alarm_info.Enabled
    $result.Type = $alarm_info.Expression.Expression.Type
    $result.Operator = $alarm_info.Expression.Expression.Operator
    $result.Red = $alarm_info.Expression.Expression.Red
    $result.Yellow = $alarm_info.Expression.Expression.Yellow
    $results += $result
}
$results | Export-Csv -NoTypeInformation -UseCulture alarms.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos