VMware Cloud Community
dhanu2k7
Enthusiast
Enthusiast

get-vievent

Hi

i am pulling events 5 month old but when I run below command it returns nothing

get-cluster -name xxxxx | Get-VIevent -Start 04/01/2017 -Finish 08/31/2017 -maxsamples 10000 | Where {$_.FullFormattedMessage -match "VMtools|VMware Tools"} | select @{Name='host';E={$_.Host.name}}, @{N='user';E={$_.UserName}},@{N='Createdtime'; E={$_.CreatedTime}}, @{N='Fullmessage';E={$_.FullFormattedMessage}} |export-csv report.csv

I also tried  -match  "Tools" but even then it returns nothings, I belive something wrong script where date is not picked up?

16 Replies
LucD
Leadership
Leadership

Try like this.
If the time formats are different in your culture, you might have to adapt the strings.

$start = Get-Date "01/04/2017"

$finish = Get-Date "31/08/2017"

Get-VIevent -Start $start -Finish $finish -MaxSamples ([int]::MaxValue) |

Where {$_.FullFormattedMessage -match "VMtools|VMware Tools"} |

select @{Name='host';E={$_.Host.name}},

    @{N='user';E={$_.UserName}},

    @{N='Createdtime'; E={$_.CreatedTime}},

    @{N='Fullmessage';E={$_.FullFormattedMessage}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

dhanu2k7
Enthusiast
Enthusiast

I need to run against cluster as there are multiple cluster

is this something below is OK?

$start = Get-Date "01/04/2017"

$finish = Get-Date "07/30/2017"

Get-cluster -Name xxxxx | Get-VIevent -Start $start -Finish $finish -MaxSamples ([int]::MaxValue) |

Where {$_.FullFormattedMessage -match "VMtools|VMware Tools"} |

select @{Name='host';E={$_.Host.name}},

    @{N='user';E={$_.UserName}},

    @{N='Createdtime'; E={$_.CreatedTime}},

    @{N='Fullmessage';E={$_.FullFormattedMessage}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

Reply
0 Kudos
LucD
Leadership
Leadership

Use the Entity parameter

$start = Get-Date "01/04/2017"

$finish = Get-Date "31/08/2017"

$entity = Get-Cluster -Name xxxx

Get-VIevent -Entity $entity -Start $start -Finish $finish -MaxSamples ([int]::MaxValue) |

Where {$_.FullFormattedMessage -match "VMtools|VMware Tools"} |

select @{Name='host';E={$_.Host.name}},

    @{N='user';E={$_.UserName}},

    @{N='Createdtime'; E={$_.CreatedTime}},

    @{N='Fullmessage';E={$_.FullFormattedMessage}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

dhanu2k7
Enthusiast
Enthusiast

its returns nothing in report.csv no error also, I am running against 6 month data for vmware tools update, i am sure there is definitely events are there but i am unable to pull

Reply
0 Kudos
LucD
Leadership
Leadership

Did you try without the Entity parameter?


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

dhanu2k7
Enthusiast
Enthusiast

Sorry without entiry also it returns immediate result without any text in report.csv

Reply
0 Kudos
LucD
Leadership
Leadership

Which events are you trying to fetch?


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

dhanu2k7
Enthusiast
Enthusiast

I am trying get who installed vmware tools on each VM...

Reply
0 Kudos
LucD
Leadership
Leadership

Afaik installing, or upgrading, VMware Tools does not generate an event.


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

dhanu2k7
Enthusiast
Enthusiast

But there is task which says Vmtools intiated ( after mounting ISO), I would like to see that

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, that is a TaskEvent, but it only shows VMware Tools updates, not installs.

The Get-VIEvent cmdlet is not recursive for the Entity parameter.

That is why we have to specify the VMs on the cluster, and not the cluster itself.

Try like this

$start = Get-Date "01/04/2017"

$finish = Get-Date "31/08/2017"

$entity = Get-Cluster -Name xxx | Get-VM

Get-VIevent -Entity $entity -Start $start -Finish $finish -MaxSamples ([int]::MaxValue) |

Where {$_ -is [VMware.Vim.TaskEvent] -and $_.Info.Name -eq 'UpgradeTools_Task'} |

select @{Name='host';E={$_.Host.name}},

    @{N='Cluster';E={$_.ComputeResource.Name}},

    @{N='user';E={$_.UserName}},

    @{N='Createdtime'; E={$_.CreatedTime}},

    @{N='Fullmessage';E={$_.FullFormattedMessage}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

avagham
Enthusiast
Enthusiast

Hello LucD - can we add Vcenter info in CSV file? if we are running script across multiple vcenters? 

Thank you!!! 

Reply
0 Kudos
LucD
Leadership
Leadership

Try adding this calculated property on the Select.

@{N='vCenter';E={([uri](Get-View -Id $_.Entity.Entity -Property Client).Client.ServiceUrl).Host}}


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

avagham
Enthusiast
Enthusiast

Hello LucD - Thanks for your help. As per recommendation I've used below command and it is working fine.

$csvline.vcenter = ([uri](Get-View -Id $event.VM.VM).Client.ServiceUrl).Host

Reply
0 Kudos
LucD
Leadership
Leadership

In this script the event is in the pipeline, so you will have to use

$csvline.vcenter = ([uri](Get-View -Id $_.VM.VM).Client.ServiceUrl).Host


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

avagham
Enthusiast
Enthusiast

Yes, Understood. Thanks for the clarification!!

Reply
0 Kudos