Skip to content

Instantly share code, notes, and snippets.

@jhochwald
Last active April 14, 2025 11:19
Show Gist options
  • Select an option

  • Save jhochwald/1f1fa9f565ae498bb37450f585008a4b to your computer and use it in GitHub Desktop.

Select an option

Save jhochwald/1f1fa9f565ae498bb37450f585008a4b to your computer and use it in GitHub Desktop.
Tweak the Windows Pagefile configuration a bit
#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
}
@jhochwald
Copy link
Author

Everything is hardcoded. So please review everything before using it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment