Before you begin
- PowerShell 7 or later on Windows.
- The Windows module or CIM performance class named in the source must be available. Protected logs and some counters require elevated read access.
Set up your example
- Save the download as monitor-pagefile-usage.ps1.
- Open PowerShell 7 in the download folder.
- Run pwsh -NoProfile -File ./monitor-pagefile-usage.ps1 -Help, then inspect its parameter block.
This recipe uses your own local input or creates its own example output. Follow the setup steps below.
Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is monitor-pagefile-usage.ps1.
Run the script
pwsh -NoProfile -File ./monitor-pagefile-usage.ps1If your system uses python3 instead of python, use that command for Python examples. Keep paths containing spaces in quotes. Required inputs and optional settings are described in the code and setup steps.
What to expect
256 MiB used from 4096 MiB produces approximately 6.3%.
The complete script
#Requires -Version 7.0
[CmdletBinding()]
param([switch]$Help,[switch]$AsJson)
$ErrorActionPreference='Stop'
if ($Help) { Write-Output 'Compare allocated, current, and peak pagefile usage in MiB. Use -AsJson for structured output.'; exit 0 }
function Show-Report { param([object]$Data) if ($AsJson) { ConvertTo-Json -InputObject @($Data) -Depth 8 } else { $Data | Format-Table -AutoSize | Out-String -Width 240 | Write-Output } }
try {
$rows = & {
Get-CimInstance Win32_PageFileUsage | Select-Object Name,AllocatedBaseSize,CurrentUsage,PeakUsage,@{n='CurrentPercent';e={if($_.AllocatedBaseSize -gt 0){[math]::Round(100*$_.CurrentUsage/$_.AllocatedBaseSize,1)}else{0}}}
}
Show-Report $rows
} catch { Write-Error $_.Exception.Message; exit 1 }
Open source as plain text · Download source and sample files
How it works
- Compare allocated, current, and peak pagefile usage in MiB.
- The script queries local Windows data and formats a snapshot without changing settings.
- -AsJson changes presentation to JSON for comparison between runs.
Make it your own
Adjust the report
Add TempPageFile to identify temporary pagefiles.
Capture JSON
Add -AsJson and redirect to a new unused filename. Shell redirection can overwrite an existing file, so choose a fresh name.
Change one setting at a time, run it again on sample data, and compare the output. The customization guide walks through this process.
If something goes wrong
A command is unavailable or access is denied.
The Windows module or CIM performance class named in the source must be available. Protected logs and some counters require elevated read access. Use only permissions you are authorized to use; protected records may require elevation.
No rows are returned.
No matching data can be valid. Remove optional filters and confirm this Windows edition exposes the requested information.
Reference & next steps
These official references explain the underlying tools. The Scriptage example and guide are original instructional content. See verification notes for what has been checked and the limits of those checks.
Copies a template for your own notes. It does not send anything.