Contributor
Contributor

Finding VM's with a created date older than x number of days

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership

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

View solution in original post

0 Kudos
5 Replies
Leadership
Leadership

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

Leadership
Leadership

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

View solution in original post

0 Kudos
Contributor
Contributor

Hi Luc

Thanks for the info - very useful - have exactly what i need now

tks

0 Kudos
Contributor
Contributor

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

  1. How many days in the past to finish at

$start = (Get-Date).AddDays(-50)

  1. How many days in the past to start from

$end = (Get-Date).AddDays(-30)

  1. 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

0 Kudos
Contributor
Contributor

hi luc

ignore my last question - i have sorted it out myself Smiley Wink

tks

Chris

0 Kudos