Original Message:
Sent: Aug 30, 2024 03:11 AM
From: LostInScripting
Subject: vCenter shows blank in output for VMHost Events Info
Tested against version 7 and 8 vCenter with PowerCLI 7.0.3.1: the returned Event Object does not have an Entity property.
v7
IpAddress : 127.0.0.1UserAgent : pyvmomi Python/3xxxx (VMkernel; 7.0.3; x86_64)CallCount : 7SessionId : 5xxxxxxxxxxxxxxxxxxLoginTime : 30.08.2024 07:09:17Key : 6x7xxxChainId : 67xx57xCreatedTime : 30.08.2024 07:09:17UserName : rootDatacenter : VMware.Vim.DatacenterEventArgumentComputeResource : VMware.Vim.ComputeResourceEventArgumentHost : VMware.Vim.HostEventArgumentVm :Ds :Net :Dvs :FullFormattedMessage : xxxxxxxxxxxxxxxxxxxxxxxxxxxChangeTag :
v8
IpAddress : 127.0.0.1UserAgent : pyvmomi 8.0xxxxx internal Python/3.xxxxxxxxx+ (VMkernel; 8.0.3; x86_64)CallCount : 7SessionId : xxxxxxxxxxxxxxxxxLoginTime : 30.08.2024 07:08:12Key : 173xxxxxxxxxxxxChainId : 1735xxxxxxxxxxxxxxCreatedTime : 30.08.2024 07:08:12UserName : rootDatacenter : VMware.Vim.DatacenterEventArgumentComputeResource : VMware.Vim.ComputeResourceEventArgumentHost : VMware.Vim.HostEventArgumentVm :Ds :Net :Dvs :FullFormattedMessage : UxxxxxxxxxxxxxxxxChangeTag :
I think the problem here seems to be that you are looking for a property in the event object that is inside the VMHost-Object.
Try this (replacing your 12th line starting with Get-VIEvent):
$thisVMHost = get-vmhost $serv; Get-VIEvent -Entity $thisVMHost -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | select @{N='vCenter';E={$thisVMHost.ExtensionData.Client.ServiceUrl}},
Original Message:
Sent: Aug 29, 2024 06:02 PM
From: LucD
Subject: vCenter shows blank in output for VMHost Events Info
And what is shown under the Entity property of the returned events?
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Aug 29, 2024 04:32 PM
From: ganapa2000
Subject: vCenter shows blank in output for VMHost Events Info
Hi LucD,
I am using vSphere 7, still I am getting the same error
No I dont see returned values are having anything like Client property
Original Message:
Sent: Aug 29, 2024 03:35 AM
From: LucD
Subject: vCenter shows blank in output for VMHost Events Info
Works for me (vSphere 8.*).
Can you check that the returned events have a value in the Client property?
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Aug 28, 2024 04:35 PM
From: ganapa2000
Subject: vCenter shows blank in output for VMHost Events Info
Hi,
For below script, I am unable to get the vCenter Information as it shows blank in the output.
Please help!!
#VMHosts List
function get-VMHostEvents()
{
$servs = @'
VMHost
ESXi01
ESXi02
'@
ForEach ($serv in (ConvertFrom-Csv -InputObject $servs).VMHost)
{
Get-VIEvent -Entity (get-vmhost $serv) -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | select @{N='vCenter';E={([uri](Get-View -Id $_.Entity.Entity -Property Client).Client.ServiceUrl).Host}},
@{N='Cluster';E={$_.ComputeResource.Name}},
@{Name='host';E={$_.Host.name}},
@{Name='IPAddress';E={$_.IPAddress}},
@{N='user';E={$_.UserName}},
@{N='Createdtime'; E={$_.CreatedTime}},
@{N='Fullmessage';E={$_.FullFormattedMessage}} -ExcludeProperty PSComputerName,RunSpaceId,PSShowComputername
}
}
get-VMHostEvents | Export-Excel -Path $reportlocation -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName VMHost_Event_Info