Configuring Pagefile using GUI and PowerShell (2021)

Configuring Pagefile using GUI and PowerShell

In day to day in life of a Windows admin, we see Memory and CPU alerts of the servers which we need to rectify. Today we are going to discuss Page files set up on the Windows server which helps us reduce the memory alerts triggered daily by the noisy servers.

Share on facebook
Share on twitter
Share on linkedin
Configuring Pagefile using GUI and PowerShell

What is a Page file?

A page file (also known as a “paging file”) is a hidden system file on a hard disk that is optional.

It is said to be optional but has added advantages which if set correctly can do wonders. Typically it is set automatically on the Windows server. If set automatically it will adjust the page file size by itself which is not always a good idea when you are running applications that use RAM extensively.

Page files allow the system to remove infrequently accessed modified pages from physical memory, allowing the system to use physical memory more efficiently for pages that are accessed more frequently.

Today we will understand how to set up the page file manually using GUI and using Powershell.

Manually configuring the Page FIle using GUI

Step #1

Open File Explorer and click on properties as shown in the screenshot.

Step #2

Click on Advance system settings as shown in the image.

Step #3

Click on Advanced and after that on the Performance section click on Settings. Performance options box will open.

Step #4

In the Performance Options window click on Advanced. Under Virtual Memory, section click on Change.

Step #5

You will be able to see that the option Automatically manage paging file size for all drives is selected. We need to unselect the option and select custom size and provide the Initial size (MB) and Maximum size (MB) to specify the value. In my case, it is 1GB and 1.5 GB( as per MS standard).

Step #6

After you have completed the click on the set and the system will ask for a reboot. Click Restart now and check the page file size it should have changed now.

Configuring the Page FIle using PowerShell

Pheww… lots of steps to digest but we have created a PowerShell script to rescue us. Here it goes!

Step #1

Before trying anything we will check the RAM size on the server so that we can make the changes on Virtual memory.

				
					#Get the installed RAM size
$physicalmem=get-wmiobject  Win32_ComputerSystem | % {$_.TotalPhysicalMemory} 
#Get the RAM size in GB
$Physicalmem1=[math]::Round($physicalmem / 1048576)
#-EnableAllPrivileges Before the command makes the WMI call, enable all of the current user's privileges.
$computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges;
#unchecks the Automatic maaged page file
$computersys.AutomaticManagedPagefile = $False;
$computersys.Put();
				
			

Step #2

Providing the Initial size and Maximum size in MB.

				
					#querying the page file settings
$pagefile = Get-WmiObject -Query "Select * From Win32_PageFileSetting Where Name like '%pagefile.sys'";
#providing initial size
$pagefile.InitialSize = 1024;
#providing maximum size
$pagefile.MaximumSize = $Physicalmem1*1.5;
#storing the values
$newpagefile=$pagefile.Put();

				
			

Step #3

Confirmation for the restart with easy if and else condition.

				
					$confirmation=Read-host "Do you want to Restart the server (Y/N)"
if($confirmation -eq 'N'){

Write-host "The system restart is skipped by the user" -BackgroundColor DarkRed

}

Else{

Write-Host "The system will be restarting ...." -BackgroundColor DarkGreen

Restart-Computer -Force
}
				
			

Conclusion

In today’s post, we have learned about the page file size and how we can manage it using GUI and PowerShell. I will return again with some awesome content. I hope you are taking some information from this post. 

close

DON’T MISS A POST

Keep up to date with PowershellGuru

SSShhhhhhh.........We don’t spam!

Powershell Blogs
Configuring Pagefile using GUI and PowerShell
Share via
Copy link
Powered by Social Snap