Tag Archives: get-vmhostalarms

Yesterday I wrote a post about getting vm alarms through PowerCLI. Today it’s time for getting host alarms 🙂 The code is very similar to the one for getting vm alarms, since they both use get-view to grab all info: $VMHosts = Get-View -ViewType HostSystem -Property Name,OverallStatus,TriggeredAlarmstate $FaultyVMHosts = $VMHosts | Where-Object {$_.TriggeredAlarmState -ne “{}”} $progress = 1 $report = @() if ($FaultyVMHosts -ne $null) { foreach ($FaultyVMHost in $FaultyVMHosts) { foreach ($TriggeredAlarm in $FaultyVMHost.TriggeredAlarmstate) { Write-Progress -Activity “Gathering alarms” -Status “Working on $($FaultyVMHost.Name)” -PercentComplete ($progress/$FaultyVMHosts.count*100) -Id 1 -ErrorAction SilentlyContinue $alarmID = $TriggeredAlarm.Alarm.ToString() $object = New-Object PSObject Add-Member -InputObject $object NoteProperty VMHost $FaultyVMHost.Name Add-Member -InputObject $object NoteProperty TriggeredAlarms (“$(Get-AlarmDefinition -Id $alarmID)”) $report += $object } $progress++ } } Write-Progress -Activity “Gathering alarms” -Status “All done” -Completed -Id 1 -ErrorAction SilentlyContinue $report | Where-Object {$_.TriggeredAlarms -ne “”} The output will look something like this: And here’s the function code: function Get-VMHostAlarms…

Read more