Tuesday, June 7, 2016

Multiple vCenter alarm at one place through PowerCLI

Write a power shell function to do this and save it as Get-TriggeredAlarms.ps1 script 
run it with this command.\Get-TriggeredAlarms -vCenters vc001,vc002
 
 
 
#Script:-
 
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" 

 
 

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...