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}}
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
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
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
I have tried the above but the get the following error:
The term 'math::round' is not recognised as a cmdlet...................
Any advise
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
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
