9

On Windows operating systems, we use the Resource Monitor to check the memory paging for my server.

I need to check it via command line so I can put in my standard script to check and create text log files.

Is there a way to check the paging memory on swap for windows, but via command line?

2
  • code your own commandline tool which calls NtQuerySystemInformation(SystemPageFileInformation) to enum page files statistic and usage Apr 8, 2016 at 4:33
  • 1
    Does the PowerShell command Get-Counter '\Paging File(*)\% Usage' give you what you need? Or get-counter '\Process(_total)\Page File Bytes'?
    – DavidPostill
    Apr 8, 2016 at 9:40

2 Answers 2

11

try this:

systeminfo | find "Virtual Memory"

this will return:

Virtual Memory: Max Size:  17.297 MB
Virtual Memory: Available: 7.186 MB
Virtual Memory: In Use:    10.111 MB

here is my powershell script that returns swap usage:

$maxSizeStr = systeminfo | select-string "Virtual Memory: Max Size:"
$maxSize = [int][regex]::Matches($maxSizeStr, '[\d.]+').Value -replace "\.",""
$inUseStr = systeminfo | select-string "Virtual Memory: In Use:"
$inUse = [int][regex]::Matches($inUseStr, '[\d.]+').Value -replace "\.",""
$swapUsage = ($inUse / $maxSize) * 100
Write-Output $swapUsage
1
  • This returns different values than the PowerShell commands @DavidPostill suggested. Maybe running both with a just rebooted system with lots of RAM can tell which one is right
    – golimar
    Sep 21, 2018 at 12:36
1

Is my powershell script returns swap usage

$colItems = get-wmiobject -class "Win32_PageFileUsage" -namespace "root\CIMV2" -computername localhost 
 
foreach ($objItem in $colItems) { 
      $allocate = $objItem.AllocatedBaseSize
      $current = $objItem.CurrentUsage
} 
write-host ($allocate - $current)
1
  • 2
    Your answer would be better if you included some example output.
    – DavidPostill
    Jun 28, 2020 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .