Automation

 View Only
Expand all | Collapse all

get-vievent

  • 1.  get-vievent

    Posted Sep 21, 2017 08:44 AM

    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?



  • 2.  RE: get-vievent

    Posted Sep 21, 2017 08:59 AM

    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



  • 3.  RE: get-vievent

    Posted Sep 21, 2017 09:03 AM

    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



  • 4.  RE: get-vievent

    Posted Sep 21, 2017 09:10 AM

    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



  • 5.  RE: get-vievent

    Posted Sep 21, 2017 09:21 AM

    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



  • 6.  RE: get-vievent

    Posted Sep 21, 2017 09:29 AM

    Did you try without the Entity parameter?



  • 7.  RE: get-vievent

    Posted Sep 21, 2017 09:53 AM

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



  • 8.  RE: get-vievent

    Posted Sep 21, 2017 10:04 AM

    Which events are you trying to fetch?



  • 9.  RE: get-vievent

    Posted Sep 21, 2017 10:28 AM

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



  • 10.  RE: get-vievent

    Posted Sep 21, 2017 10:32 AM

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



  • 11.  RE: get-vievent

    Posted Sep 21, 2017 01:31 PM

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



  • 12.  RE: get-vievent

    Posted Sep 21, 2017 01:49 PM

    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



  • 13.  RE: get-vievent

    Posted Sep 23, 2020 05:46 PM

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

    Thank you!!! 



  • 14.  RE: get-vievent

    Posted Sep 23, 2020 06:13 PM

    Try adding this calculated property on the Select.

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


  • 15.  RE: get-vievent

    Posted Sep 23, 2020 07:43 PM

    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



  • 16.  RE: get-vievent

    Posted Sep 23, 2020 07:47 PM

    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



  • 17.  RE: get-vievent

    Posted Sep 23, 2020 07:49 PM

    Yes, Understood. Thanks for the clarification!!