VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

get-vievent per vcenter

i am trying to get a list of alerts from each vcenter but I need to list the vcenter name along with each event.

how do i do this?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can loop through all connected vCenters, and do something like this

foreach($vc in $global:DefaultVIServers){

    Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) -Server $vc |

    where{$_ -is [VMware.Vim.AlarmEvent]} |

    Select CreatedTime,@{N='Alarm';E={$_.Alarm.Name}},From,To,

        @{N='vCenter';E={$vc.Name}},

        @{N='Entity';E={$_.Entity.Name}}

}

    


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

View solution in original post

Reply
0 Kudos
3 Replies
mvelezwhiteFFI
Contributor
Contributor
Jump to solution

A good friend of mine in these forums was helping me with a similar problem.  I had created a script that connected to all my vCenters (28 of them!!!).  Then I was doing a report on the inventory of VMs.  One of the items I needed was the vCenter where it came from.  To do this, a calculated field is needed.  I'm still learning this process because it applies to other things you may wish to use.  Anyway, pay attention to the @{ N= statements, there's the clue for what you needed.  If you're still having trouble, let me know.

This may work for you, just substitute the properties that you need to report on instead:

Get-VM |

Select Name,

    @{ N = 'vCenter'; E = { $_.Uid.Split('/')[1].Split('@')[1] } },

    @{ N = 'VMHost'; E = { $_.VMhost.Name } },

    @{

  N = 'CreationDate'; E = {

  Get-VIEvent -Entity $_ -MaxSamples ([int]::MaxValue) |

  where { $_ -is [VMware.Vim.VmCreatedEvent] } |

  Sort-Object -Property CreatedTime -Descending |

  Select -First 1 |

  Select -ExpandProperty CreatedTime

  }

} | Export-Csv E:\<path to>\yourfilename.Csv

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can loop through all connected vCenters, and do something like this

foreach($vc in $global:DefaultVIServers){

    Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) -Server $vc |

    where{$_ -is [VMware.Vim.AlarmEvent]} |

    Select CreatedTime,@{N='Alarm';E={$_.Alarm.Name}},From,To,

        @{N='vCenter';E={$vc.Name}},

        @{N='Entity';E={$_.Entity.Name}}

}

    


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

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

very nice. didnt realize there was a -Server option for get-vievent

Reply
0 Kudos