PowerShell Script to set the size of pagefile.sys

Jayu picture Jayu · Jun 14, 2016 · Viewed 23.5k times · Source

How to set the size of Page File on Windows(pagefile.sys) via PowerShell?

Answer

Pratik Patil picture Pratik Patil · Jun 14, 2016

This is how we can update the size of pagefile.sys via PowerShell:

# PowerShell Script to set the size of pagefile.sys

$computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges;
$computersys.AutomaticManagedPagefile = $False;
$computersys.Put();
$pagefile = Get-WmiObject -Query "Select * From Win32_PageFileSetting Where Name like '%pagefile.sys'";
$pagefile.InitialSize = <New_Value_For_Size_In_MB>;
$pagefile.MaximumSize = <New_Value_For_Size_In_MB>;
$pagefile.Put();

Execute the script as below:

PS> .\update_pagefile_size.ps1;