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?
That looks correct.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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"
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
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?
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
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?
From the VM property, like this
$event.VM.Uid.Split(":")[0].Split("@")[1]
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK great - thanks again - just to clarify - is this correct?:
@{N="vCenter Server";E={$_.VM.Uid.Split(":")[0].Split("@")[1]}}
That looks correct.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
great much appreciated
can you pls post your final script here ?