"Exception calling "Put" with "0" arguments "value out of range" - Not able to Set pagefile through powershell according with RAM size

jimmy afflick 21 Reputation points
2022-08-25T11:30:47.617+00:00

My requirement is to Setpage file in C drive through powershell, my requirement is clear I have explained it below.

*Set the paging file size to a value that is 1.5 times the physical random access memory (RAM) size.
***1) 1.5 times the physical RAM size (RAM <=32)
2) 60 GB (RAM >32)****

While I am trying to set the pagefile, I am getting below error

"Exception calling "Put" with "0" arguments "value out of range".

$PageFile.Put() its the culprit which is causing the issue,.

I have attached the powershell code below after the website link. Please have a look. What am I doing wrong? Can you recommend a better way of doing it?. Kindly help me to solve this issue experts.

I am looking forward to hear from you. Thanks.

I have got an powershell code to set pagefile from below microsoft link

https://social.technet.microsoft.com/Forums/windowsserver/en-US/8cd191bc-3746-44cb-b639-b5bcbdc55de6/setting-pagefile?forum=winserverpowershell

Uncheck Automatic manage pagefile to set pagefile manually

$sys = Get-WmiObject Win32_Computersystem –EnableAllPrivileges
$sys.AutomaticManagedPagefile = $false
$sys.put()

Setting Pagefile

$PageFile = Get-WmiObject -class Win32_PageFileSetting
$RAM = [Math]::Round((Get-WmiObject Win32_OperatingSystem).TotalVisibleMemorySize / 1kb)
if ($RAM -lt 32768)
{
$PageFile.InitialSize = [uint32]($RAM * 1.5)
$PageFile.MaximumSize = [uint32]($RAM * 1.5)

}
else
{
$PageFile.InitialSize = 61440
$PageFile.MaximumSize = 61440
}
$PageFile.Put()

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,635 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 32,911 Reputation points
    2022-08-25T13:26:12.033+00:00

    I was able to recreate your error. You do not have sufficient free space on the C drive to set a page file to the size that you set.

    You can use Get-Volume to report on the free space. You will need to either delete some files or change the size value.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. jimmy afflick 21 Reputation points
    2022-08-25T22:07:56.573+00:00

    @MotoX80

    You are great. Your guessing is right, that error came because of the lack of space in that particular drive. I accepted your answer. Its the right answer. Thank you.