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

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(-30)

 

# 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, User, VmName, Cluster, Host, Msg
     $row.Date = $_.createdTime
     $row.Msg = $_.fullFormattedMessage
     $row.User = $_.userName
     $row.VMName = $_.vm.name
     $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 | Export-Csv "C:\VMCreated.csv" -NoTypeInformation


Any ideas why this is drawing a blank when I know there are servers that were created less than 7 days ago?


Viewing all articles
Browse latest Browse all 181285

Trending Articles



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