Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

Script to count PoweredOn VMs in multiple vCenters

$
0
0

I have a script that will give me the total count of Powered on VMs in each environment, but I would love for it to automatically add the values together and display an overall total, instead of exporting each vCenter's count to a CSV. 

 

For example, I'd like it to see total VC01=100, VC02=200, VC03=50, VC04=250, VC05=100.  Total = 700 Powered On VMs. 

 

Anyone have any suggestions? 

 

------------------------

 

# Build array for each vCenter with vDS switch

  $array = "vc01", "vc0e", "vc0e", "vc04", "vc05"

  for($count=0;$count -lt $array.length; $count++)

{

# Connect to All vCenter Servers, one at a time.

connect-viserver $array[$count]

 

# Get VM counts & export to CSV

Get-VMHost | Get-VM | where-object {$_.PowerState -eq "PoweredOn"}| Measure-Object | export-csv -notypeinformation c:\ben\vmware\$($array[$count])_vm_count.csv

 

# Disconnect from vCenter Servers

disconnect-viserver -confirm:$false

}

 

------------------------

 

Thanks in advance!


Viewing all articles
Browse latest Browse all 175326

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>