2

In Linux we can:

grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'

What are the alternatives in Windows command prompt and PowerShell? I will run this command from ruby.

I have tried using:

wmic memorychip get /VALUE | findstr "Capacity" 

to get the prefixed output of available bytes. But I need to get only numeric value out of it. And I could not find anything like sed in Windows.

7
  • Have you made any effort to find out yourself? Is there anything in particular you're stuck with? Commented Mar 3, 2015 at 13:23
  • 2
    An easy google nets a WMI query (Get-WmiObject Win32_PhysicalMemory | measure-object Capacity -sum).sum/1gb Commented Mar 3, 2015 at 13:32
  • @arco444, yes, I have the wmic memorychip get /VALUE | findstr "Capacity" command giving me prefixed output of available bytes. But I need to get only numeric value out of it. And I could not find anything like sed in windows, so I could complete this one-liner. Commented Mar 3, 2015 at 13:35
  • @arco444 but I also assume that command will fail on localized Windows environments. Commented Mar 3, 2015 at 13:35
  • 1
    Pure CLI solution wmic memorychip get Capacity|find /I /V "y". Use find or findstr command, in this case the output should be the same Commented Mar 3, 2015 at 14:28

1 Answer 1

1

For a simple PowerShell answer this simple approach is brought to you by "Deranged PowerShell Zealot" from BrianDesmond.com. Look at the comments and not the blog post.

(Get-WmiObject Win32_PhysicalMemory | measure-object Capacity -sum).sum/1gb

That will return the GB value of memory installed on the computer. You can substitute 1gb for 1mb depending on your output needs.

If you are looking for a batch type solution consider adding that tag but understand that those solutions will most likely require for loops to parse the string tokens (I dont know for sure) so getting a one liner might not be as clean as you expect.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.