VMware Cloud Community
piglet
Enthusiast
Enthusiast

Query around a) VM created date b) VM last-turned-on date

Folks,

First off, may I thank you chaps (and ladies) for many of the interesting posts that I'm seeing on this particular forum. I frequently come here looking for the answer to one problem, and leave with solutions to 3 other things that I didn't know were causing me problems. Great stuff indeed.

Anyhow, on to the main event... similar to Mr. pfuhli here (http://communities.vmware.com/thread/135962), I like the idea of weekly/monthly reporting for my overlords. In part this is motivated by showing how clever I am, but more technically it's to do with capacity planning and such like. It would be great to have a weekly mail that stated something like:

a) x new VMs have been created in the last week (followed by list of names)

b) This adds to y VMs that have been created in the past 4 weeks (or calendar month, or whatever, obvsiouly same mechanism as "a)")

c) z VMs have not been turned on for over 12 weeks, and decommissioing should be considered.

Now, while a snapshot seems to have a .created property, I can't see the same thing for a VM. Does it exist? If not, can we do something clever around the age of a .vmx file, or parse logs/VC events for a relevant entry around VM creation? Option c) may require ingenuity too, since we're essentially looking for something that's absent, or non-present...

Suggestions welcome.

Many thanks,

piglet

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

There don't seem to be properties that would allow one to calculate the age of a guest.

In the SDK the VirtualMachineConfigInfo has a property named " modified" but that only shows the last time the guest's configuration was changed.

The only alternative I can see is to use a CustomProperty (see ).

That would allow you to create for example a CustomProperty called "CreatedOn" with a date value.

Then it would be easy to run a script that gets the value, calculates the difference in number of days and puts the guest in the correct report.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

angoletti1
Contributor
Contributor

Hi,

what do you think about using the created date of the VMX file and the last changed date of the first VMDK file?

Not a very good solution, but maybe one the could work.

CUSNE
Contributor
Contributor

Have you found a way to do this? I have been asked to provide this information and am not having any luck finding a solution.

Thanks

Mark

Reply
0 Kudos
piglet
Enthusiast
Enthusiast

Hi Mark,

I ended up rooting about in the VC DB, and came up with the following syntax to run as a query:

select CREATE_TIME, USERNAME, VM_NAME, HOST_NAME, DATACENTER_NAME

from VPX_EVENT

Where EVENT_TYPE = 'vim.event.VmCreatedEvent' OR EVENT_TYPE = 'vim.event.VMClonedEvent' AND CREATE_TIME > '2007-06-01'

While this could be driven by PS, I ended up doing things more manually.

The requirement for the .vmclonedevent entries stems from the fact that a 'new' VM from the PoV of the DB seems to be one that has been manually created new, not pne imported from Converter nor cloned.

Hope this is of help.

piglet

Reply
0 Kudos
kcvman
Contributor
Contributor

When running against my DB, I received multiple creation dates for the same guest. I did verify this by having DRS vmotion a guest to another host within a cluster, re-ran the query, and after the vmition by DRS, that host had 2 seperate created entries on 2 seperate hosts.

Still hoping for a solution on this...

Reply
0 Kudos
Anaxander
Enthusiast
Enthusiast

<bump>

Anyone find a solution to this? This would be really good information to have.

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee

This can now be achieved using the get-vievent cmdlet as shown below where we get the last 5 days of VMs created and cloned:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-5) | where {$_.Gettype().Name -eq "VmCreatedEvent" -or $_.Gettype().Name -eq "VmBeingClonedEvent"}

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
EdConde
Contributor
Contributor

I am getting time out errors, is there a way to increase the time out?

thanks!

Reply
0 Kudos
robincm
Contributor
Contributor

If most of your VMs are running Windows then you might find my post on historic reporting of VM creation date (actually OS install date) useful:

Get VMware VM creation date (kind of)

Will fairly easily give you a nice graph for your capacity planning/amusement/horror.

Reply
0 Kudos