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?
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
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
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
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
Did you try without the Entity parameter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry without entiry also it returns immediate result without any text in report.csv
Which events are you trying to fetch?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am trying get who installed vmware tools on each VM...
Afaik installing, or upgrading, VMware Tools does not generate an event.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
But there is task which says Vmtools intiated ( after mounting ISO), I would like to see that
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
Hello LucD - can we add Vcenter info in CSV file? if we are running script across multiple vcenters?
Thank you!!!
Try adding this calculated property on the Select.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
Yes, Understood. Thanks for the clarification!!