9

I have this:

(Get-WMIObject Win32_logicaldisk -computername computer).TotalPhysicalMemory

to get size of physical memory installed on remote computer. How do I get the FREE memory of that computer?

I've tried

(Get-WMIObject Win32_logicaldisk -computername computer).FreePhysicalMemory

and some other variants, but with no effect. Is there some list of possible "filters"?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
culter
  • 5,487
  • 15
  • 54
  • 66

5 Answers5

14

Whenever you want to see all of the properties of an object, pipe it to Format-List *.

Get-WmiObject Win32_LogicalDisk | format-list *
Get-WmiObject Win32_OperatingSystem | fl *

Or if you are looking for a particular propery, you can use wildcard search

Get-WmiObject Win32_OperatingSystem | fl *free*

As Aquinas says, you want the Win32_OperatingSystem class, FreePhysicalMemory property. Win32_LogicalDisk tracks hard disks, not RAM.

latkin
  • 16,402
  • 1
  • 47
  • 62
10

You can also try the Get-Counter cmdlet:

(Get-Counter -Counter "\Memory\Available MBytes" -ComputerName computer).CounterSamples[0].CookedValue
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
4

You want Win32_OperatingSystem not Win32_logicaldisk I believe.

aquinas
  • 23,318
  • 5
  • 58
  • 81
1

So putting together the other answers:

get-ciminstance Win32_OperatingSystem | % FreePhysicalMemory

Remotely:

invoke-command computer { get-ciminstance Win32_OperatingSystem | % FreePhysicalMemory } 
js2010
  • 23,033
  • 6
  • 64
  • 66
  • I believe this should really be `Get-CimInstance Win32_OperatingSystem`. `Get-WmiObject` was deprecated since PowerShell 3.x and removed since PowerShell 6.x. – TheFreeman193 Mar 01 '21 at 22:52
0

Free memory of the local machine (use -computername foo for a remote one):

(Get-WMIObject Win32_OperatingSystem).FreePhysicalMemory  # in KB

19793740
(Get-WMIObject Win32_OperatingSystem).FreePhysicalMemory / 1MB  # in GB

18.8592491149902

Might seem weird to divide by 1MB to get GB, but the original number is just given in KB. The result is actually no different from writing * 1KB / 1GB (which you can also use).

xjcl
  • 12,848
  • 6
  • 67
  • 89