Server Core Page File Management with Powershell

A quickie for tonight.

(Heh heh...)

Microsoft is really pushing to make this command line-only, Server Core and Powershell thing happen. No more GUI. Everything needs to get done on the command line. Wooo command line. Love it.

So... how the heck do you set the size and location of the paging file(s) without a GUI? Could you do it without Googling Binging? Right now?

You will be able to if you remember this:

$PageFileSizeMB = [Math]::Truncate(((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory + 200MB) / 1MB)
Set-CimInstance -Query "SELECT * FROM Win32_ComputerSystem" -Property @{AutomaticManagedPagefile="False"}
Set-CimInstance -Query "SELECT * FROM Win32_PageFileSetting" -Property @{InitialSize=$PageFileSizeMB; MaximumSize=$PageFileSizeMB}

The idea here is that I'm first turning off automatic page file management, and then I am setting the size of the page file manually, to be static and to be equal to the size of my RAM, plus a little extra. If you want full memory dumps in case your server crashes, you need a page file that is the size of your physical RAM plus a few extra MB.

You could have also done this with wmic.exe without using Powershell, but when given a choice between Powershell and not-Powershell, I pretty much always go Powershell.

Did I mention Powershell?

Comments (2) -

space ghost 7/2/2014 11:15:29 AM

I don't see where you set the location.

You can't arbitrarily change the location (name attribute) of an existing pagefile. You can, however, delete the existing pagefile and create a new one.

# Delete pagefile(s)
(Get-WmiObject -Class Win32_PageFileSetting).Delete()
# Create a new one at 'S:\pagefile.sys' with init/max sizes
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = 'S:\pagefile.sys'; InitialSize = $PageFileSizeMB; MaximumSize = $PageFileSizeMB }

Comments are closed