VMware Cloud Community
crosen
Contributor
Contributor

Find number of VMs created/deleted for a given period?

Is there a way to determine the number of VMs that were created and deleted for a given time frame (i.e., 24 hours, 1 week, 1 month)? Thanks.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Have a look at .

It show how to find the removed VMs for the last 5 days.

By changing the -Start parameter you can chose another time range.

For VMs that were created use "VmCreatedEvent" in the Where-Object cmdlet.


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

crosen
Contributor
Contributor

Here is my code, but the info that it is returning is inaccurate. I've run it against my three VC servers and all are incorrect considering I know I have created/deleted more than this is returning.

$VCServerName = "vcname"

connect-viserver -server $VCServerName -user $User -password $Password

$Removed80 = Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-14) | where {$_.Gettype().Name -eq "VmRemovedEvent"}

$Created80 = Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-14) | where {$_.Gettype().Name -eq "VmCreatedEvent"}

$Removed80Count = $Removed80.Length

$Created80Count = $Created80.Length

Echo "VMs removed last 14 days:"

$Removed80Count

Echo "VMs created last 14 days:"

$Created80Count

Disconnect-VIServer -Confirm:$False

0 Kudos
crosen
Contributor
Contributor

Can I get this data by querying the SQL DB?

0 Kudos
LucD
Leadership
Leadership

Yes you can, but I would advise you not to use this path since the internals of the VC db are not documented.

So it could be that your query won't work anymore after a patch or an upgrade.

See for an example on accessing the VC db.


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

0 Kudos