In vSphere, version 5, when you click on a resource pool and hit the summary tab, in the Memory box under resource settings you can see something like:
Reservation: 0.00MB
Limit: 48:00GB
Configured 29:00GB.
I want to be able to pull out that number for "Configured" with powercli. Then I can see what pools are over or under allocated.
I believe it can be found in a property called summary.configuredMemoryMB from ResourcePoolSummary, but I have no idea how to use either of these objects. I have tried.
I am able to get the Limit, which is MemLimitGB. Here is my script:
**********************************************************************************
I would like:
Try it like this
$report = @() foreach ($pool in Get-ResourcePool) { $row = "" | Select Name, ParentID, MemLimitGB, Parent, "VC", "CONFIGMEM"
$row.Name = $pool.Name
$row.ParentID = $pool.ParentID
$row.MemLimitGB = [int]$pool.MemLimitGB
$row.Parent = $pool.Parent
$row."VC" = $vc
$row."CONFIGMEM" = $pool.ExtensionData.summary.configuredMemoryMB
$report += $row
} $report | Export-Csv
To reach the vSphere ResourcePool object, you go through the ExtensionData property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD thanks for the reply.
This doesn't work. It doesn't give any error, it just gives a blank value.
The CONFIGMEM property was missing from the Select, or did you already fix that ?
Just tried it in my test environment, and I get the correct value.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, thatnks very much, this works.
I didn't see that you had made some changes at the beginning of the script.
I just worked it out another way. Inside the foreach loop, at the top, I added the line:
$vm = Get-ResourcePool -name $pool.name | Get-vm
then further down I added:
$row."CONFIGMEM" = "{0:f1}" -f [int](($vm | Measure-Object -Property MemoryGB -Sum).Sum)
that worked. But I'm going to stick with your method and I changed it slightly to:
$row."CONFIGMEM" = [int]($pool.ExtensionData.summary.configuredMemoryMB/1024)
So again thanks. This has resolved my question.
Roger
Hi LucD and Roger,
LucD very efficient, I was looking for something almost exactly similar.
A quick question, as I am not brilliant with PowerShell, is it possible to Nest the foreach function.
The report outputs, for each cluster, report Resource pool.
Would it be possible to do something more detailed like, for each cluster report resource pool, then for each resource pool report VM useage?
Yes, that is possible.
But there a couple of things you should keep in mind:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow that was a quick reply, I was worried that this thread was a bit old.
I had my own basic Get-VM line:
Get-VM | Select Name,MemoryGB,@{n="Mem Resource Limit";E={Get-VMResourceConfiguration -VM $_ | Select -ExpandProperty MemLimitGB}},@{n="Mem Reservation";E={Get-VMResourceConfiguration -VM $_ | Select -ExpandProperty MemReservationGB}},NumCpu,@{n="CPU Limit";E={Get-VMResourceConfiguration -VM $_ | Select -ExpandProperty CpuLimitMhz}}| Export-csv c:\temp\virtualmachinesettings.csv
But liked the idea of scripting it the way you did.
Probably I could get away with
Having a report with For each pool and then list the VMs. Personally I have a need for what cluster they are on.
But even the line I use above is a tad intensive as I am pulling so many values.
I used separate scripts.
I run a getCluster script and then a getResourcePool script.
My scripts run through 7 VCs, the list of VCs being held in a file, vc.txt.
Each script writes to it's own csv file.
The scripts, amoung other things, get the the ID of the main resource pools and the parent ID for each resource pool.
In your getVM script you can extract the ID of the pool the VM is in.
These IDs give you a link between the csv files.
I upload the files to a linux machine, run shell scripts use grep, sed and awk etc, where I cross reference the csv files using pool and parent IDs, and then output to .html files that I display on Apache. These web pages summarize all the clusters and show how much memory they have what's in use and what's left, and also show a list of all resource pools, with memory limit and memory configured.
This allows me to see in a glance if clusters are running out of resources. It also allows me to see if a pool is configured for more memory than allocated, or perhaps using a lot less memory than allocated. Either one indicates and problem.
We have a dynamic environment so these scripts run 4 times a day.
Roger
I was wondering more about the foreach function though.
And how to nest commandlets, there are other cases where I would like to get information about a device and highlight its parent.
For example the Get-NetworkAdapter, I cant manage to get the name of the vm its connected to.
For Get-networkadapter, not following what you want to do.
Get-networkadapter -vm NAME-OF-VM | select networkname, parent
will give you the portgroup name and the vm name. But the command asks that you specify a VM, Template or Snapshot. How are you trying to use it?
Here's one way to do it:
This will give you a csv filer per vcenter. The csv file will have VC, Cluster, Pool, memory etc for each VM.
It gives you the port group to which the VM is connected.
Although this is the reverse of what you were asking, which is what VM is connected to the port group?
And just a note for your csv file, a VM maybe connected to more than one port group so this will give a number of entries in that field spearated by a space.
Your original question was to get "for each cluster, report resource pool, then for each resource pool report VM usage'
So for each cluster, report what about each resource pool? Just it's name? Or a group of other stats? If you need stats from the pool, then you'd probably be best with separate scripts. If you just want VM stats and want to know what cluster and resource pool the VM belongs to, then I think this will do it.