Search code examples
powershellpagefile

Pagefile error with error code "Set-WmiInstance : Value out of range"


I am trying to set pagefile size for C and D drive with the following code. But there is an odd issue with this. Sometimes the code will work perfectly. Sometimes it will throw an error saying

Set-WmiInstance : Value out of range

for both drives. And sometimes it will throw that error only for C or D drive.

Can anyone know the reason?

Note: I test this code in my laptop only.

Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{
    Name        = "C:\pagefile.sys";
    InitialSize = 800;
    MaximumSize = 1600
}
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{
    Name        = "D:\pagefile.sys";
    InitialSize = 1600;
    MaximumSize = 3200
}

Solution

  • I know what is the problem and how to fix it.

    1. Disable Auto Manage PageFile Setting for All drives
    2. Delete Existing Page File
    3. Change the drive to System Manage
    4. Set the pagefile for the drives

    These tricks help me to set the pagefile with whatever number I want