How to get pagefile settings using PowerShell?


Pagefile also Known as Virtual Memory file in the Windows Operating system is a very useful part of the OS. It helps to reduce the burden on the Physical memory by storing some paging file in the file call Pagefile.sys. Generally, this file in windows OS is stored in C:\ unless it is modified.

You can check the Pagefile settings in the Windows GUI using

System Properties → Advanced → Performance → Settings → Advanced → Virtual Memory → Change.

We have made a few blocks and circles in the above pagefile properties image. We will see them one by one.

First, to check if pagefile is automatically managed or not as shown in the first circle, we will use the below command.

PS C:\> (Get-CimInstance Win32_ComputerSystem).AutomaticManagedPagefile

Output:

True

In the above image, the pagefile is automatically managed so the output is true.

Second, we need to know if the pagefile is system managed or customized, you need to use CIMInstance or WMI class Win32_PageFileSetting, but the condition here is if the pagefile is automatically managed then the output will be Null because in the image itself you can see that System managed part is disabled.

So let's assume on one server Automatic pagefile management is disabled and when we use the Win32_pagefilesetting command then we will get the details below.

Get-CimInstance Win32_PageFileSetting | fl *

Output:

Caption               : c:\ 'pagefile.sys'
Description           : 'pagefile.sys' @ c:\
SettingID             : pagefile.sys @ c:
InitialSize           : 0
MaximumSize           : 0
Name                  : c:\pagefile.sys
PSComputerName        :
CimClass              : root/cimv2:Win32_PageFileSetting
CimInstanceProperties : {Caption, Description, SettingID, InitialSize...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

In the above output, we have InitialSize and MaximumSize that mentions the custom size of the pagefile. If both are 0 then the pagefile is managed by the system.

Third, to know the pagefile drive and what is it current and peak usage, we need to use the CIMInstance method with class Win32_PagefileUsage class.

PS C:\Users\Administrator> Get-CimInstance Win32_PageFileUsage | fl *

Output:

Status :
Name : C:\pagefile.sys
CurrentUsage : 85
Caption : C:\pagefile.sys
Description : C:\pagefile.sys
InstallDate : 7/5/2020 12:01:30 PM
AllocatedBaseSize     : 1024
PeakUsage             : 127
TempPageFile          : False
PSComputerName        :
CimClass              : root/cimv2:Win32_PageFileUsage
CimInstanceProperties : {Caption, Description, InstallDate, Name...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

You can see the AllocatedBaseSize (i.e Currently allocated), TempPageFile (to check if temporary pagefile is created or not), and the CurrentUsage of the pagefile.

Unfortunately, we can’t get the Recommended size using PowerShell because it is managed by the system and the size changes as per system requirement.

You can get all page file settings mentioned above on the remove computers using -ComputerName parameter.

Updated on: 05-Oct-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements