VMware Cloud Community
peter79
Enthusiast
Enthusiast
Jump to solution

Finding out when a host was added to my VC?

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos