paul_hobbs
Contributor
Contributor

Get-VIevent scripting problem

I want to extract the information from get-vievent 1st to get the vm information and use it to generate a VM disconnected information.

In this flow, I use "Get-VIevent" to generate to some logs like "disconnected".

But I found that there is no VM name information for get-vievent for next step to get-vm.

How can I process it?

Get-vievent | get-vm ?

VM Name, VM Description, Error Created time, Error description

Ususally, I found some related topics , get-vm 1st and get-vievent to filter the events but it will take longer time if my inventory is too big

0 Kudos
3 Replies
LucD
Leadership
Leadership

Did you already try the Entity parameter on the Get-VIEvent cmdlet ?

$vms = Get-VM

$events = Get-ViEvent -Entity $vms

Which event are you looking at ?


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

0 Kudos
mrchiu
Contributor
Contributor

I have a similar scripting problem on this.

From lucD 's suggestion, I try to write as this

$vms = Get-VM

Get-ViEvent -Entity $vms-MaxSamples 10000 -Start (Get-Date).AddDays(-1) | Where-Object {$_.FullFormattedMessage -LIKE '*was restart
ed on*'} | Select Name, Description, CreatedTime, FullFormattedMessage

I try to run the script. It seems to take a longer timer to run all VM inventory.

I want to extract VM restarts log in the server and generate the information like this:

VM name , Error Time, Error Message, VM Description.

But I can't find "Get-vievent " any option on it

0 Kudos
LucD
Leadership
Leadership

The Get-VIEvent has a rather limited set of parameters.

You can use the Types parameter to filter the returned events, but that is about it I'm afraid.

There rest of the filtering will need to be done by Where-clauses in the script.


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

0 Kudos