Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 229203

Re: Get VM Create Date & Time

$
0
0

Hi,

I’m also getting the CSV created but it’s empty. I ran the below and got a positive response indicating 4 counts which I assume are 4 VMs created.

PowerCLI C:\> Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) |
Where-Object {$_.GetType().Name -eq "VmCreatedEvent"} |
Measure-Object

Count    : 4
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

This is the script Im running in a .PS1 file. Does it matter if this is run on 5.1 as was written when 4.1 was the most current?


# How many days in the past to start from
$start = (Get-Date).AddDays(-10)

# The more days back, the higher this number should be.
$eventNr = 9999

$report = @()

Get-VIEvent -Start $start -MaxSamples $eventNr | `
Where-Object {$_.GetType().Name -eq "VmCreatedEvent"} | % {
     $row = "" | Select Date, Msg, User, Cluster, Host
     $row.Date = $_.createdTime
     $row.Msg = $_.fullFormattedMessage
     $row.User = $_.userName
    
     $t = New-Object VMware.Vim.ManagedObjectReference
     $t.type = $_.computeResource.computeResource.type
     $t.Value = $_.computeResource.computeResource.Value
     $row.Cluster = (Get-View $t).Name

     $t.type = $_.host.host.type
     $t.Value = $_.host.host.Value
     $row.Host = (Get-View $t).Name
    
     $report += $row
}
$report

Many thanks


Viewing all articles
Browse latest Browse all 229203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>