skip to Main Content

Pagefile Exchange 2013/2016 best practice PowerShell

How to configure the pagefile in Exchange Server 2013/2016 with PowerShell? In one of the previous articles, we talked about Pagefile Exchange 2013/2016 best practice. Read the article to understand the best practice of the pagefile. What if you don’t want to do the math and manually edit the pagefile on the Exchange Server? For example, you want to set the page file on many Exchange Servers. This will take time. What if you can run a script, and it does it all? PowerShell to the rescue.

Configure Exchange Server pagefile with PowerShell

I came across the following post by Damian Scoles. He made a script to configure the pagefile of the Exchange Server 2013/2016. Download the Set-PagefileExchange2013-2016.ps1 PowerShell script. Save the script in your c:\scripts\ folder. Run the PowerShell script as administrator.

If you like, you can copy the script below and paste it into PowerShell. After you run the script, it will tell show you precisely what it’s doing. If you get an error, the script will show why. For example, if you don’t have enough space on the disk drive.

# Variable
$Computername = $Env:ComputerName
# Get RAM and set ideal PageFileSize
try {
    [int32]$RamInMb = (Get-CIMInstance -computername $Name -Classname win32_physicalmemory -ErrorAction Stop | measure-object -property capacity -sum).sum/1MB
} catch {
    Write-Host "Cannot acquire the amount of RAM in the server." -ForegroundColor Red
    $Stop = $True
[int32]$Size = $RAMinMb + 10
# Set Maximum Pagefile Size
If ($Size -gt 32778) {
    $Size = 32778
# Disk Space Check
$Disk = Get-WmiObject Win32_LogicalDisk -ComputerName $ComputerName -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$MB = $Disk.FreeSpace/1mb
$FreeSpace = [Math]::Round($MB)
if ($FreeSpace -lt $Size) {
    Write-Host "There isn't enough diskspace available for configuring the Pagefile to the correct size." -ForegroundColor Yellow
    Write-Host "The Pagefile needs to be $Size MB and the amount of freespace is $FreeSpace MB." -ForegroundColor White
} Else {
    Write-Host " "
    Write-Host "The Pagefile will be set to a Maximum size of $Size MB and a Minimum size of $Size MB." -ForegroundColor Yellow
    Write-Host " "
    # Set the Automatic Pagefile to False
    Set-CimInstance -Query “Select * from Win32_ComputerSystem” -Property @{AutomaticManagedPagefile=”False”}  -ErrorAction STOP
    # Remove the old Pagefile
    $PageFile = Get-CimInstance -ClassName Win32_PageFileSetting
    $PageFile | Remove-CimInstance
    # Set the Pagefile to the new size
    New-CimInstance -ClassName Win32_PageFileSetting -Property  @{Name= "$("C"):\pagefile.sys"}
    Get-CimInstance -ClassName Win32_PageFileSetting | Set-CimInstance -Property @{InitialSize = $Size; MaximumSize = $Size}
    # End Result
    $Pagefile = Get-CimInstance Win32_PageFileSetting -Property * | Select-Object Name,InitialSize,MaximumSize
    $Name = $;$Max = $Pagefile.maximumsize;$Min = $Pagefile.initialsize
    Write-Host " "
    Write-Host "The page file of $Name is now configured for an initial size of " -ForegroundColor White -NoNewline
    Write-Host "$Min " -ForegroundColor Green -NoNewline
    Write-Host "and a maximum size of " -ForegroundColor White -NoNewline
    Write-Host "$Max." -ForegroundColor Green
    Write-Host " "
    Write-Host "DON'T FORGET TO REBOOT THE SERVER!!!" -ForegroundColor Red

You have set the recommended page file on the Exchange Server. Don’t forget to reboot the Exchange Server.

Read more: Pagefile Exchange 2019 best practice PowerShell »


We showed how to change the Exchange Server 2013/2016 pagefile with PowerShell. Run the script, and it will configure the pagefile on the Exchange Server 2013/2016. Don’t forget to reboot after the change! This script should only run in Exchange Server 2013/2016. Not on other Exchange Server versions.

It’s a great script and does the job. If you have many Exchange Servers and want to change the pagefile, make your life easier and run the script. Will you be using the PowerShell script in your Exchange Server 2013/2016? I recommend using the script.

Did you enjoy this article? You may also like Get mailbox size of all users in Exchange with PowerShell. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *