Guys,
I have a script that generates a list of all hosts in my enviroment. It gives me the host name as well as ESX version and build number. Is there any way I can modify the script so it shows me when each host was added to the VC?
Thanks.
Yes, you can use the Get-VIEvent cmdlet to retrieve events and look for the HostAddedEvent entries.
Something like this
$daysBack = 1
$report = @() Get-VIEvent -Start (Get-Date).AddDays(-$daysBack) -MaxSamples 99999 | `
where{$_.GetType().Name -eq "HostAddedEvent"} | %{ $row = "" | Select HostName,DC,Cluster,Date,User $row.HostName = (Get-View $_.Host.Host).Name $row.DC = $_.Datacenter.Name $row.Cluster = $_.ComputeResource.Name $row.Date = $_.CreatedTime $row.User = $_.UserName $report += $row
} $report
Note that the Get-VIEvent cmdlet by default only returns 100 events even when you specify a -Start parameter.
So you have to give a sufficiently large number on the -MaxSamples parameter to retrieve all the events for the period you're investigating.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, you can use the Get-VIEvent cmdlet to retrieve events and look for the HostAddedEvent entries.
Something like this
$daysBack = 1
$report = @() Get-VIEvent -Start (Get-Date).AddDays(-$daysBack) -MaxSamples 99999 | `
where{$_.GetType().Name -eq "HostAddedEvent"} | %{ $row = "" | Select HostName,DC,Cluster,Date,User $row.HostName = (Get-View $_.Host.Host).Name $row.DC = $_.Datacenter.Name $row.Cluster = $_.ComputeResource.Name $row.Date = $_.CreatedTime $row.User = $_.UserName $report += $row
} $report
Note that the Get-VIEvent cmdlet by default only returns 100 events even when you specify a -Start parameter.
So you have to give a sufficiently large number on the -MaxSamples parameter to retrieve all the events for the period you're investigating.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference