Hello Everyone,
Can we get the lists of recently added VM's to VC or environment on a weekly basis or daily basis from power cli?
thanks
vmk
You can do something like this
Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.VmCreatedEvent]}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
i tried but it throws an error for timeout..
PS C:\temp> .\VM-created.ps1
Get-VIEvent : 01/03/2019 4:36:09 AM Get-VIEvent The request channel timed out while waiting for a reply
after
00:04:59.9884200. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the
Binding. The time allotted to this operation may have been a portion of a longer timeout.
At C:\temp\VM-created.ps1:1 char:1
+ Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VIEvent], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetEvent
Ouch, that could mean there is a massive amount of events, or your VCSA is very busy.
You can try to increase the timeout with (default is 300 seconds).
where{$_ -is [VMware.Vim.VmCreatedEvent]}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did change to 1 day but still, it runs forever
Like I said, could have multiple causes:
Start with a small interval.
Change the AddDays(-1) to AddHours(-1)
Not really a PowerCLI issue, more a performance issue in your environment.
Did you also change the timeout?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you also change the timeout? - No didn't changed yet
But you don't get the timeout exception anymore?
Are you perhaps connected to multiple vCenters?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
But you don't get the timeout exception anymore? No not getting any timeout exception
Are you perhaps connected to multiple vCenters? No
Did you get result?
Otherwise try smaller intervals for the Start parameter (Get-Date).AddHours(-1)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok I changed to 1 hour after getting a timeout error but it appears not result.
It looks like you might have an issue on that vCenter.
Try further increasing the WebOperationsTimeoutSeconds option.
This thread even mentions going as far as 3600 seconds :smileyshocked:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference