Search code examples
powershellsystempagefile

PowerShell Script to set the size of pagefile.sys


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


Solution

  • 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;