VMware Cloud Community
woodycollins
Contributor
Contributor

Virtual Machine Configuration

I've been trying to get an understanding on the powercli commands and am just having a horrible time understanding things.  Is it possible to collect a listing of vm's in virtual center and from that collected list, get the configuration information per vm for such things as processor, memory, drives (and datastore the drives are located on)?

Sorry if this seems very simplisted but I have literally been looking into this for over 12 hours today and can't seem to find out how to simply get the virtual machines hard drive information alone.

Please any help.

Reply
0 Kudos
6 Replies
ae_jenkins
Enthusiast
Enthusiast

Well, I think part of the confusion is you are sorta looking for two seperate items, as far as VMware is concerned.  If you just want the VM information, that's easy:

get-vm  | select name, memorymb, numcpu | sort name

The hard disks are a bit trickier, since VMware views it as an array with a relationship to the virtual machine itself.  So to go deeper:

get-vm  | get-harddisk | select parent, name, filename | sort parent, name

The second entry will give you HD information.  To tie them together will require a loop...let me see if I have a stock script I can post.

Reply
0 Kudos
ae_jenkins
Enthusiast
Enthusiast

This should work - sorry that the formatting is a bit weird.

Connect-VIServer YourVcenterServer

$report = @()

$path = $HOME + '\desktop\vmhdlist.csv'

$vm = Get-VM | sort name

foreach

($vmitem in $vm)

{

$vmhd = $vmitem | Get-HardDisk

foreach ($vmdisks in $vmhd)

{

$list = "" | select vmname, RAMMB, numCPU, HDname, hdfile

$list.vmname = $vmitem.name

$list.rammb = $vmitem.memorymb

$list.numcpu = $vmitem.numcpu

$list.hdname = $vmdisks.name

$list.hdfile = $vmdisks.filename

$report += $list

}

}

 

$report

| Export-Csv -Path $path -notypeinformation

woodycollins
Contributor
Contributor

Excellent.  Thank your for the information.  By chance do you know if its possible to pull the average mhz usage per vm as well?

Reply
0 Kudos
ae_jenkins
Enthusiast
Enthusiast

Yeah, there's lots of stuff at

$vmitem.extensiondata.summary.quickstats

If you don't see what you need there, it would require some drill-down using the 'get-stat' cmdlet

Reply
0 Kudos
woodycollins
Contributor
Contributor

Thank you for all your help.  I've figurd out most of what I am looking for thanks to you.  One thing I am running into trouble understanding is the CPU Ready Time.  I understand what it is but I am stumbling on understanding what I need to calculate to convert the millisecond count into a percentage. Say for instance I run the command "Get-Stat -Entity vmname -stat CPU.Ready.Summation | Measure-Object value -average "  It spits out a result of something like count: 4, average 6764455.

Now that average is in milliseconds.  Would I then have to take my collection time (which is default), multiply that by the count number, divide it into the average number and then multiply by .1?  For example given the numbers above:

20,000*4 = 80,000

6764455 / 80000 = 84.555

84.555 * .1 = 8.4%

The end result looks correct to me, but I want to make sure.  Also if it is right how would you extract the "count" number returned by the command so I can put it into a script line to calculate everything for me?  An example would be helpfull, or if anyone knows of a better way to do it that would work as well.

Reply
0 Kudos
LucD
Leadership
Leadership

The cpu.ready.summation returns a delta value, see the CPU metrics table.

The description is not correct imho, the metric is returning a value in milliseconds, not a percentage.

The Measure-Object cmdlet provides you the average over all the returned values.

Afaik, you don't need the count in the percentage calculation, but you do need the length of the returned intervals.

I use something like this

$vm = Get-VM MyVM 
$stats
= Get-Stat -Entity $vm -stat CPU.Ready.Summation
$averageSecs
= ($stats | Measure-Object value -average).average / 1000
$interval = $stats[0].IntervalSecs $percent = $averageSecs / $interval Write-Host "CPU Ready" ("{0:P}" -f $percent)


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

Reply
0 Kudos