VMware Cloud Community
Fender84
Contributor
Contributor

Question regarding querying vmware events using powerCLI

I'm trying to optimize the code below. It runs fine and gives me the results I need, but it takes close to 15 mins to run. Is there any way to optimize it? Basically I just want to output events for the last 14 days to pull information on who added a specific tag for a server and the timestamp it was added. As I mentioned the code below works perfectly and gets me exactly what I need, I just hope to speed it up. Thanks in advance!

foreach($DC in (Get-Datacenter | Get-Unique))
{
    # Configure DC Variable
    $DC = $DC.Name

    if($DC -eq "DC01")
    {
        ##DC01
        $vCenter = "server1"
    }
    if($DC -eq "DC02")
    {
        ##DC02
        $vCenter = "server2"
    }

    (Get-VIEvent -Server $vCenter -Start (Get-Date).AddDays(-14) -MaxSamples ([int]::MaxValue) -Types Info) | Where-Object {($_.EventTypeId -eq 'com.vmware.cis.tagging.attach') -AND ($_.FullFormattedMessage -like "*Backup*")} | Select FullFormattedMessage, CreatedTime
 }

 

0 Kudos
2 Replies
LucD
Leadership
Leadership

You could try with my Get-VIEventPlus function, that is most of the time faster than the Get-ViEvent cmdlet.


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

0 Kudos
Fender84
Contributor
Contributor

Thank you that was a huge help. It runs MUCH faster!

0 Kudos