VMware Cloud Community
Pinball
Enthusiast
Enthusiast

Get number of created and deleted vm's per cluster

Hi there

Below is a part of a much bigger script I use to get some vm capacities from 14 different virtual centers and then write the results back to a sql database for reporting.

The intention is to get the number/quantity of vm's created and deleted by cluster on a daily base.

I've got the below but the result is always 0 and not the correct value. I have a source script that connects to the vc and calls the below in part.

param($cluster)

$clus =Get-cluster $cluster

$start = (Get-Date).Adddays(-1)

$vmnewcount = ($clus | Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where {@("VMCreatedEvent") -contains $_.GetType().Name} | measure-object).Count

$vmdelcount = ($clus | Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where {@("VMRemovedEvent") -contains $_.GetType().Name} | measure-object).Count

New-Object PSObject |

Add-Member -pass NoteProperty "VMsCreaed"           $vmnewcount   |

Add-Member -pass NoteProperty "VMsDeleted"           $vmdelcount  

Result:

VMsCreaed  : 0

VMsDeleted : 0

A second pair of eyes will be appreciated to see what i'm missing here.

Thanks

0 Kudos
3 Replies
Madmax01
Expert
Expert

HI theire,

i changed little the code. its working on my side with this Code:

could you test Smiley Wink

$clus =Get-cluster xxxxxx

$start = (Get-Date).Adddays(-7)

$vmnewcount = ($clus |Get-VIEvent -maxsamples ([int]::MaxValue)  -Start $start | where {$_.Gettype().Name-eq "VmCreatedEvent"} |measure-object).count

$vmdelcount = ($clus |Get-VIEvent -maxsamples ([int]::MaxValue)  -Start $start | where {$_.Gettype().Name-eq "VMRemovedEvent"} |measure-object).count

New-Object PSObject |

Add-Member -pass NoteProperty "VMsCreaed"           $vmnewcount   |

Add-Member -pass NoteProperty "VMsDeleted"           $vmdelcount

0 Kudos
Pinball
Enthusiast
Enthusiast

Hi MadMax01

Thanks for the reply, doesn't matter what i try i always get "0" events, but when i just do a "Get-VIEvent" i get the events i'm interested in for the last few days. Just not able to display the count  for yesterday.

Johan

0 Kudos
Madmax01
Expert
Expert

Hi,

hm that's very strange. Code was working on my side and giving me values for both Back.

if you say manually is working > then this is confusing me. ha.

- Which Powercli Version you use?  i tested with 6.0 R1

thx

Max

0 Kudos