VMware Cloud Community
Guv
Enthusiast
Enthusiast
Jump to solution

memory value in GB

I am running the below script to get a spec for my esx hosts. The memory value I am getting is a long number and I think its in KB. Is there anyway I can turn the script to give me the memory value in GB. Any advise.

get-vmhost | get-view | select name, @{ N = "model"; E = { $_.summary.hardware.model}},@{ N = "Cpumodel"; E = { $_.summary.hardware.cpumodel}}, @{ N = "Cpumhz"; E = { $_.summary.hardware.cpumhz}},@{ N = "Memory"; E = { $_.summary.hardware.memorysize}}

Reply
0 Kudos
1 Solution

Accepted Solutions
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Try this:

get-vmhost | get-view | select name, @{ N = "model"; E = { $_.summary.hardware.model}},@{ N = "Cpumodel"; E = { $_.summary.hardware.cpumodel}}, @{ N = "Cpumhz"; E = { $_.summary.hardware.cpumhz}},@{ N = "Memory"; E = { [Math]::round($_.summary.hardware.memorysize /1GB)}}

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com

View solution in original post

Reply
0 Kudos
6 Replies
aerodevil
Hot Shot
Hot Shot
Jump to solution

Powershell is awesome because you can do the math right up front and simply divide by KB, MB, or GB

$memoryKB = get-vmhost | get-view | select name, @{ N = "model"; E = {

$_.summary.hardware.model}},@{ N = "Cpumodel"; E = {

$_.summary.hardware.cpumodel}}, @{ N = "Cpumhz"; E = {

$_.summary.hardware.cpumhz}},@{ N = "Memory"; E = {

$_.summary.hardware.memorysize}}

$memoryGB = ($memoryKB / 1GB)

More info about this can be seen at

Josh Atwell

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Try this:

get-vmhost | get-view | select name, @{ N = "model"; E = { $_.summary.hardware.model}},@{ N = "Cpumodel"; E = { $_.summary.hardware.cpumodel}}, @{ N = "Cpumhz"; E = { $_.summary.hardware.cpumhz}},@{ N = "Memory"; E = { [Math]::round($_.summary.hardware.memorysize /1GB)}}

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
Guv
Enthusiast
Enthusiast
Jump to solution

I have tried the above but the get the following error:

The term 'math::round' is not recognised as a cmdlet...................

Any advise

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Are you putting the square brackets around math ?

[math]::round

as above

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
Guv
Enthusiast
Enthusiast
Jump to solution

cheers mate, your a life saver.

How long did it take you to learn powershell, I want to become more expert as well, been using last 2 months powershell for vmware

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

It probably took me around 6 months tobe more confident but I am still learning today, I dont think I will ever stop learning.

Keep at it, one day it will just all click !

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos