I wasn't able to convert to javascript yet, but I did clean up the script. If you want to play around with it, please feel free. I ran this against a test environment with no issues. It WILL cough up an error about not being able to find the "resources" resource pool, but continues to run normally.
#add VCLI snapin
Add-PSsnapin VMware.VimAutomation.Core
#connect to vCenter server specified by user
$vCenterServer = read-host "Please enter vCenter server name"
#username and password can be specified here. Be careful as to what password is provided as whoever can see this script can know the password.
#$userName = read-host "Please input username"
#$userPassword = read-host "please input password"
#gather credentials for individual run
$myCredentials = Get-Credential
#connect to VCenter server with credentials from user
connect-viserver $vCenterServer -Credential $myCredentials
#connect to vCenter server with credentials specified in script
#connect-viserver $vCenterServer -username $userName -password $userPassword
#set resource pool gathering
#can specify resource pool name here using "". Right now is set to calculate ALL resource pools.
$ResourcePools = Get-ResourcePool
#main loop to look at every resource pool in vCenter
foreach ($ResourcePool in $ResourcePools)
{
$numvcpus = 0
$totalmemory = 0
$numvms = 0
$pool = Get-ResourcePool -Name $ResourcePool
#gathers information about the resource pool
foreach ($VM in ($pool| get-VM | where {$_.Powerstate -eq "PoweredOn"})) #checks only for VMs that are powered on
{
#count number of CPUs
$NumvCPUs += ($VM).NumCpu
#count how much memory is allocated
$TotalMemory += ($vm).MemoryMB
#count number of VMs
$NumVMs += 1
}
#dislays output
Write-Host "Discovered " $NumvCPUs "running vCPUs in resource pool " $ResourcePool
Write-Host $TotalMemory "MB of memory allocated in resource pool" $ResourcePool
Write-Host "Discovered " $NumVMs "running virtual machines in resource pool " $ResourcePool
#calculates the CPU and MEM into the type of share values you need
$PoolCPUShares = 1000 * $NumvCPUs
$PoolMemShares = ($TotalMemory / 1024) * 1000
#sets the resource pool values based on what is gathered
Set-Resourcepool -Resourcepool $Pool -CPUsharesLevel Custom -NumCpuShares $PoolCPUShares -MemSharesLevel Custom -NumMemShares $PoolMemShares
}
I think the easiest way to do this is to get the Powershell plugin and have VCO call the powershell script from a utility server we have set up. I'm not good enough with javascript to do the conversion.
Message was edited by: Unkyrona