RayofCommand
RayofCommand

Reputation: 4244

Output free Memory as single value in Mega Bytes

i am searching for a solution, i want to get my free memory space as single value in MB.

When i for example out-file it, i always get time stap etc.

for me it doesn't matter wheter we get the result by get-counter or get-wmiobject.

i tried it this way and ofc i always get the full message outfiled...

get-wmiobject win32_operatingSystem FreephysicalMemory

Get-Counter -Counter "\Memory\Available MBytes"

Thank you in advance!

ray

Upvotes: 1

Views: 1234

Answers (1)

Shay Levy
Shay Levy

Reputation: 126842

$mem = Get-Counter -Counter "\Memory\Available MBytes"
$mem.CounterSamples[0].CookedValue

or

# FreephysicalMemory is represented in kb, devide it in 1kb to get the value in mb
(get-wmiobject win32_operatingSystem FreephysicalMemory).FreePhysicalMemory/1kb

Upvotes: 3

Related Questions