Hi LucD,
I can able to full the connection status using the below script.
My question is like can we use if loop to combine both script ?
if uptime < 100% then pull the hostname and use the below script to find the connection status.
Instead of again running this script manually for all host?
$esx = Get-VMHost host5
Get-VIEvent -Entity $esx -MaxSamples 99999 -Start (Get-Date).AddDays(-30) | `
where {"HostConnectionLostEvent","HostConnectedEvent" -contains $_.GetType().Name} | `
Sort-Object -Property {$_.CreatedTime.DateTime} -Unique | `
Select @{N="Hostname";E={$_.Host.Name}},
@{N="Time";E={$_.CreatedTime.ToShortDateString() + " " + $_.CreatedTime.ToShortTimeString()}},
@{N="Status";E={if($_.GetType().Name -eq "HostConnectedEvent"){"Connected"}else{"Not connected"}}}
"Hostname","Time","Status"
"host5","18/05/2020 10:20","Not connected"
"host5","18/05/2020 10:29","Connected"
"host5","19/05/2020 09:56","Not connected"
"host5","19/05/2020 10:30","Connected"