Skip to content

Instantly share code, notes, and snippets.

@lazerl0rd
Last active March 2, 2021 15:37
Show Gist options
  • Save lazerl0rd/69930693d168fa2c105982543abedaf9 to your computer and use it in GitHub Desktop.
Save lazerl0rd/69930693d168fa2c105982543abedaf9 to your computer and use it in GitHub Desktop.
A function to report swap usage and certain configurations on Windows.
Function Get-PageFileInfo
{
$compSysResults = Get-CimInstance Win32_ComputerSystem -Namespace 'root\cimv2'
$pageFileResults = Get-CimInstance -Class Win32_PageFileUsage -ComputerName $Computer | Select-Object *
$pageFiles = $pageFileResults.Description
$pageFileCurrentSizes = $([string]$pageFileResults.CurrentUsage).Split(" ")
For ($i = 0; $i -lt $pageFileCurrentSizes.length; $i++)
{
$pageFileCurrentSizes[$i] = $pageFileCurrentSizes[$i] + "MB"
}
$pageFilePeakSizes = $([string]$pageFileResults.PeakUsage).Split(" ")
For ($i = 0; $i -lt $pageFilePeakSizes.length; $i++)
{
$pageFilePeakSizes[$i] = $pageFilePeakSizes[$i] + "MB"
}
$pageFileTotalSizes = $([string]$pageFileResults.AllocatedBaseSize).Split(" ")
For ($i = 0; $i -lt $pageFileTotalSizes.length; $i++)
{
$pageFileTotalSizes[$i] = $pageFileTotalSizes[$i] + "MB"
}
Write-Host "Automatically Managed : $($compSysResults.AutomaticManagedPagefile)`n"
For ($i = 0; $i -lt $pageFiles.length; $i++)
{
Write-Host "File Path : $($pageFiles[$i])"
Write-Host "Total Size : $($pageFileTotalSizes[$i])"
Write-Host "Current Usage : $($pageFileCurrentSizes[$i])"
Write-Host "Peak Usage : $($pageFilePeakSizes[$i])"
Write-Host "Temporary Page File In Use : $($pageFileResults.TempPageFile[$i])"
If ($i -lt $($pageFiles.length - 1))
{
Write-Host ""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment