VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Reporting on VMs created

Is there a way to use PowerCLI to read into the events during a given period of time, and to determine how many VMs were created during that time?  For example, from 15 days ago to 45 days ago?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That looks correct.


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

View solution in original post

Reply
0 Kudos
11 Replies
LucD
Leadership
Leadership
Jump to solution

You can use the same method as I mentioned in here Someone removed the custom attributes field

You would be looking for the VmCreatedEvent event (and possible the VmClonedEventevents and VmDeployedEvent events).

Count the number of returned events for the period and you should have the number.

Let me know if you need more help with the script ?


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

TheVMinator
Expert
Expert
Jump to solution

OK great thanks.  Can you tell me how I can add the name of the VM that was created to the report? I want to both report on the fields below, and count the number of VMs in them.  How can I add a count to the following code?

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-62) -finish (Get-Date).adddays(-30) | where {$_.Gettype().Name -eq "VmCreatedEvent",

"VmClonedEvent","VmDeployedEvent"} | Select createdTime, userName,fullFormattedMessage | export-csv -path "c:\vms.txt"

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VIEvent -maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-62) -finish (Get-Date).adddays(-30) | 
where {"VmCreatedEvent","VmClonedEvent","VmDeployedEvent" -contains $_.Gettype().Name} |
Select createdTime, userName,@{N="VM";E={$_.VM.Name}},@{N="Host";E={$_.Host.Name}}


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

TheVMinator
Expert
Expert
Jump to solution

OK thanks - works great.  Can I also add to the report fields which list the total size of all virtual disks on each VM and the total RAM allocated to each VM, and add those fields to the existing columns created by this report?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you can, under the VM property of the event you have access to the complete VirtualMachine object.

The same object that you would get when you do a Get-VM


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

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK great thanks.  I was able to pull that info with your suggestion.  One last question - how do I get the name of the vcenter server that this VM is connected to?  I'm running the report against multiple vcenter servers at once, so I want to create a column that lists which vcenter server this particular VM was created in.  What would that look like?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

From the VM property, like this

$event.VM.Uid.Split(":")[0].Split("@")[1]


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

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK great - thanks again - just to clarify - is this correct?:

@{N="vCenter Server";E={$_.VM.Uid.Split(":")[0].Split("@")[1]}}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That looks correct.


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

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

great much appreciated

Reply
0 Kudos
esxi1979
Expert
Expert
Jump to solution



can you pls post your final script here ?

Reply
0 Kudos