i am looking for some code that will list me VM's that were created more than 30 days ago. I have seen the code where i can see what has been created within x number of days, but was wondering how i can list vm's created after x number of days. I have played around but do not seem to be able to get anything to work ;-(
As usual any assistance would be most welcome !!
tks
Have a look at Events: a great source of information – Part 1, which shows 2 methods of getting the information you're after.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you running VI or vSphere ?
And how long do you keep the events ?
The normal way to do this would be to use the Get-ViEvent cmdlet and scan for the events that are related to VM creation.
Something like Carter's blog entry where he does something similar for VM powerons.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at Events: a great source of information – Part 1, which shows 2 methods of getting the information you're after.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
Thanks for the info - very useful - have exactly what i need now
tks
hmmm ... one further thing Luc if i may,
I have used the following way of identifying vm's that were created between 30 and 50 days ago .... what i would like to know is how i would get the script to put in the Guest Name - at the moment the Guest name is part of the full text string and im having problems picking this out ... any idea how i can add vm name in to the query and display it in its own column ?
tks
chris
How many days in the past to finish at
$start = (Get-Date).AddDays(-50)
How many days in the past to start from
$end = (Get-Date).AddDays(-30)
The more days back, the higher this number should be.
$eventNr = 20000
#VM Creation date information
$report = @()
Get-VIEvent -Finish $end -Start $start -MaxSamples $eventNr | `
Where-Object {$_.GetType().Name -eq "VmCreatedEvent"} | %{
$row = "" | Select Date, Msg, User
$row.Date = $_.createdTime
$row.Msg = $_.fullFormattedMessage
$row.User = $_.userName
$report += $row
}
$report
hi luc
ignore my last question - i have sorted it out myself
tks
Chris