VMware Cloud Community
vmk2014
Expert
Expert

Can we get the lists of Recently added VM's ?

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

Tags (1)
0 Kudos
11 Replies
LucD
Leadership
Leadership

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

0 Kudos
vmk2014
Expert
Expert

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

0 Kudos
LucD
Leadership
Leadership

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).

Set-PowerCLIConfiguration -WebOperationTimeoutSeconds 600 -Confirm:$false

Or else, collect the events for a smaller period.
Check if this works, then we can do 7 collects, each for 1 day.

Get-VIEvent -Start (Get-Date).AddDays(-1) -MaxSamples ([int]::MaxValue) |

where{$_ -is [VMware.Vim.VmCreatedEvent]}


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

0 Kudos
vmk2014
Expert
Expert

I did change to 1 day but still, it runs forever

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

Like I said, could have multiple causes:

  • big amount of events
  • slow vCenter

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

0 Kudos
vmk2014
Expert
Expert

Did you also change the timeout?  - No didn't changed yet

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vmk2014
Expert
Expert

But you don't get the timeout exception anymore?  No not getting any timeout exception

Are you perhaps connected to multiple vCenters? No

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vmk2014
Expert
Expert

Ok I changed to 1 hour after getting a timeout error but it appears not result.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos