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

2.6k Views Asked by At

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
}
2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

InitialSize Data type: uint32

Access type: Read/write

Qualifiers: MappingStrings ("Win32Registry|System\CurrentControlSet\Control\Session Manager\Memory Management|PagingFiles"), Units ("megabytes")

MaximumSize Data type: uint32

Access type: Read/write

Qualifiers: MappingStrings ("Win32Registry|System\CurrentControlSet\Control\Session Manager\Memory Management|PagingFiles"), Units ("megabytes")

Could you please try this once:

Set-WmiInstance Win32_PageFileSetting -Arguments @{Name='D:\pagefile.sys'; InitialSize=128; MaximumSize=512}