You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Relocate pagefile using powershell

This short guide explains how to set pagefile configuration using powershell.

Daniel Nachtrub
Daniel Nachtrub

It may happen to you that you're working on headless systems (or just use remote powershell, because you can) and you want to adjust the location of the pagefile.

Mostly, you'll do this using the UI on the advanced system settings page.

This works fine and is easy to use. Yet it's not that fast as you've to navigate through a ton of popups.

Just as most stuff on windows, the configuration is done using WMI under the hood and can therefore be accessed using scripting languages - in our case powershell.

Configure pagefile using powershell

Setting pagefile configuration using powershell involves accessing WMI to:

  • Disable managed pagefile
  • Remove current pagefile configuration
  • Create a new pagefile configuration

The script looks as follows:

# get a handle on the system settings
$cs = Get-WmiObject Win32_computersystem -EnableAllPrivileges
 
# disable managed pagefile
$cs.AutomaticManagedPagefile = $false
$cs.Put()
 
# get a handle on current pagefile configuration and remove it
$pf = Get-WmiObject -Query "select * from Win32_PageFileSetting"
$pf.delete()
 
# create a new pagefile configuration
# in this case we're creating the pagefile on c:
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="c:\pagefile.sys"; InitialSize = 8192; MaximumSize = 16384}
adjust pagefile

That's it already - as usual you need to reboot for these settings to apply.

WindowsPowershell

Daniel Nachtrub

Kind of likes computers. Linux foundation certified: LFCS / CKA / CKAD / CKS. Microsoft certified: Cybersecurity Architect Expert & Azure Solutions Architect Expert.