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()