Last active
April 14, 2025 11:19
-
-
Save jhochwald/1f1fa9f565ae498bb37450f585008a4b to your computer and use it in GitHub Desktop.
Tweak the Windows Pagefile configuration a bit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #requires -Modules CimCmdlets | |
| #requires -Version 2.0 | |
| # Disable AutomaticManagedPagefile | |
| $YourSys = (Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction SilentlyContinue) | |
| If($YourSys.AutomaticManagedPagefile) | |
| { | |
| try | |
| { | |
| $YourSys | Set-CimInstance -Property @{ | |
| AutomaticManagedPageFile = $false | |
| } -ErrorAction Stop | |
| } | |
| catch | |
| { | |
| Write-Warning -Message $_.Exception.Message | |
| } | |
| } | |
| # Configure Drive C | |
| $DriveLetter = 'C' | |
| try | |
| { | |
| $PageFile = (Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($DriveLetter):'" -ErrorAction Stop) | |
| $null = ($PageFile | Remove-CimInstance -ErrorAction SilentlyContinue) | |
| } | |
| catch | |
| { | |
| Write-Verbose -Message 'Pagefile did not exist. who cares?' | |
| } | |
| $null = New-CimInstance -ClassName Win32_PageFileSetting -Property @{ | |
| Name = "$($DriveLetter):\pagefile.sys" | |
| } | |
| try | |
| { | |
| $null = Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($DriveLetter):'" -ErrorAction Stop | Set-CimInstance -Property @{ | |
| InitialSize = 10240 | |
| MaximumSize = 20480 | |
| } | |
| } | |
| catch | |
| { | |
| Write-Warning -Message $_.Exception.Message | |
| } | |
| # Configure Drive D | |
| $DriveLetter = 'D' | |
| try | |
| { | |
| $PageFile = (Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($DriveLetter):'" -ErrorAction Stop) | |
| $null = ($PageFile | Remove-CimInstance -ErrorAction SilentlyContinue) | |
| } | |
| catch | |
| { | |
| Write-Verbose -Message 'Pagefile did not exist. who cares?' | |
| } | |
| $null = New-CimInstance -ClassName Win32_PageFileSetting -Property @{ | |
| Name = "$($DriveLetter):\pagefile.sys" | |
| } | |
| try | |
| { | |
| $null = Get-CimInstance -ClassName Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $($DriveLetter):'" -ErrorAction Stop | Set-CimInstance -Property @{ | |
| InitialSize = 102400 | |
| MaximumSize = 204800 | |
| } | |
| } | |
| catch | |
| { | |
| Write-Warning -Message $_.Exception.Message | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everything is hardcoded. So please review everything before using it!