1 Reply Latest reply on Dec 17, 2010 7:53 AM by LucD

    Finding out when a host was added to my VC?

    peter79 Enthusiast



      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?



        • 1. Re: Finding out when a host was added to my VC?
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Yes, you can use the Get-VIEvent cmdlet to retrieve events and look for the HostAddedEvent entries.

          Something like this


          $daysBack = 1 
          = @() 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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz