1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
param (
[String[]]$vCenters
)
Function Get-TriggeredAlarms {
param (
$vCenter = $(throw "A vCenter must be specified."),
[System.Management.Automation.PSCredential]$credential
)
if ($credential) {
$vc = Connect-VIServer $vCenter -Credential $credential
}
else {
$vc = Connect-VIServer $vCenter
}
if (!$vc) {
Write-Host "Failure connecting to the vCenter $vCenter."
exit
}
$rootFolder = Get-Folder -Server $vc "Datacenters"
foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {
$alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime
$alarm.VC = $vCenter
$alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name
$entity = Get-View -Server $vc $ta.Entity
$alarm.Entity = (Get-View -Server $vc $ta.Entity).Name
$alarm.EntityType = (Get-View -Server $vc $ta.Entity).GetType().Name
$alarm.Status = $ta.OverallStatus
$alarm.Time = $ta.Time
$alarm.Acknowledged = $ta.Acknowledged
$alarm.AckBy = $ta.AcknowledgedByUser
$alarm.AckTime = $ta.AcknowledgedTime
$alarm
}
Disconnect-VIServer $vCenter -Confirm:$false
}
Write-Host ("Getting the alarms from {0} vCenters." -f $vCenters.Length)
$alarms = @()
foreach ($vCenter in $vCenters) {
Write-Host "Getting alarms from $vCenter."
$alarms += Get-TriggeredAlarms $vCenter
}
$alarms | Out-GridView -Title "Triggered Alarms"
|