VMware Cloud Community
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

Get VM's creation date

It's possible to get the exact creation time of a VM?

I'm seeing here in the tasks and events but ain't found. Maybe some PowerCli cmdlet exclusive for reports?

33 Replies
LucD
Leadership
Leadership
Jump to solution

That is a function, you have to call the function.

You could do, from the PowerCLI prompt

PS> . .\filename.ps1

PS>  Get-VMCreationTimes

With the first command you dot-source the .ps1 file, as a result the function is now known in the PS engine. Note that there is a blank between the 2 dots.

The 2nd command calls the function and should produce some results


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

0 Kudos
falconbuban
Contributor
Contributor
Jump to solution

Hi Luc, thank you very much for your reply, it's working now! I am newbie on PS and dummy at the same time Smiley Happy. Is there a way to pipe this into file like export-csv or > c:\vmcreationdate.txt?

Thank you again guys.

0 Kudos
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

you can use the export-csv like this>

(your command) | export-csv c:\YourFile.csv

or

(your command) >>c:\YourFile.csv

it will work too in many cases.

0 Kudos
falconbuban
Contributor
Contributor
Jump to solution

Hi GuilhermeStela, it works!

This is what I did:

PS> . .\filename.ps1

PS>  Get-VMCreationTimes >> c:\MyFile.csv

Thank you guys again! Take care!

0 Kudos
sivaksk147
Contributor
Contributor
Jump to solution

Hi,

I am getting below error:

Attempted to divide by zero.
At line:9 char:7
+       $percentComplete = $vmevts.count / $vms.count * 100
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
Write-Progress : Cannot validate argument on parameter 'PercentComplete'. The argument is null, empty, or an element of the argument collection contains a null value.
Supply a collection that does not contain any null values and then try the command again.
At line:10 char:84
+ ... ercentcomplete $percentComplete
+                    ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Write-Progress], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WriteProgressCommand
If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could it be that Get-VM returns 0 or 1 VMs ?


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

0 Kudos
oktoberfestbier
Contributor
Contributor
Jump to solution

Hi folks,

the ps script works, but the is  createdTime is wrong, the VM´s are only 1 or 2 months

old.

Has anybody a tip to solve this issue.

regards

Dominik

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which script are you using ? The one from May 15th 2012 ?

What kind of creation dates you get returned ?


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

0 Kudos
oktoberfestbier
Contributor
Contributor
Jump to solution

yes i have use the scipt from the second site of this blog

this is my output from the text file

createdTime                   name                          IPAddress                     createdBy
14.06.2012 02:13:01           xxx                     {0.0.0.0, 192.168.10.68}      xxxx/xxx             
14.06.2012 02:36:40           xxxx                     {192.168.10.175}              xxxx/xx            
14.06.2012 03:00:53           xxx

the oldest entry is form the 06.14.2012

regards

dominik

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And what should be creation dates according to you ?

Could it be that these VMs are perhaps re-created at some point with the same display name ?


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

0 Kudos
oktoberfestbier
Contributor
Contributor
Jump to solution

the most of the vm´s are one or two years old

my retetion date form the vcenter is 180 days

The vm´s are not re-created

dominik

0 Kudos
robincm
Contributor
Contributor
Jump to solution

If most or all of your VMs run Windows then you'll possibly find that the OS install date corresponds fairly well with the VM creation date. I've got a Powershell/PowerCLI script that'll collect this info into a CSV file and allow you to fairly easily see how things have grown over time.

So it's not quite what you're after, but could be enough of an approximation to be useful.

See Get VMware VM creation date (kind of) on my blog.

0 Kudos
drowland
Contributor
Contributor
Jump to solution

it seems that the dates coorespond to a snapshot removal or something.  It is showing we created 1000's of VM's in the past couple of months..  We've created a lot, but not quite that much.


My output is as follows for one VM:

11/28/2013 1:37:19 AM          xlserver.domain.com

If I look in vCenter at the tasks for that server, I see the following at the same time:

Task: Remove snapshot

info

11/28/2013 1:37:19 AM

Remove snapshot

xlserver.domain.com

smvi

We are using NetApp's SMVI utility so I'm not sure if that is the issue.  The user for the above entry was SMVI.  I'm also seeing a lot of entries for VM's listing com.springsource.vfabric as the username...

0 Kudos
JuanJesusMendoz
Contributor
Contributor
Jump to solution

Hello, can you help me, how execute script please. :smileygrin:

Thanks.

0 Kudos