This PowerShell Script illustrates how to adjust virtual memory page file size.
During deployment, customers want to adjust virtual memory page file size on several PCs. This is also useful to the customers who are not familiar with the calculating the value for the virtual memory or operating in the user interface.
Step 1: Click Start, type powershell in the search box on the Start Menu, right-click the
Windows PowerShell icon, and then click Run Windows PowerShell as administrator. If the
User Account Control dialog box appears, confirm that the action it displays is what you want, and then click
Continue.

Step 2: Run the script in the Windows PowerShell Console, type the one command:
Import-Module <Script Path> at the prompt. For example, type
Import-Module G:\Script\AdjustVirtualMemoryPagingFileSize.psm1 This is shown in the following figure.

Step 3: You can type the command Get-Help Set-OSCVirtualMemory
to display the entire help file for this function, such as the syntax, parameters, or examples.

Step 4: If you want to adjust virtual memory page file size on “D” and “E” drive, then you can type the command
Set-OSCVirtualMemory -InitialSize 1024 -MaximumSize 2048 -DriveLetter "D:","E:"
for example as below

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
Try
{
If($PageFile -ne $null)
{
$PageFile.Delete()
}
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{name="$DL\pagefile.sys"; InitialSize = 0; MaximumSize = 0} `
-EnableAllPrivileges |Out-Null
$PageFile = Get-WmiObject Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $DL'"
$PageFile.InitialSize = $InitialSize
$PageFile.MaximumSize = $MaximumSize
[Void]$PageFile.Put()
Write-Host "Execution Results: Set page file size on ""$DL"" successful."
Write-Warning "Pagefile configuration changed on computer '$Env:COMPUTERNAME'. The computer must be restarted for the changes to take effect."
}
Catch
{
Write-Host "Execution Results: No Permission - Failed to set page file size on ""$DL"""
}
Try { If($PageFile -ne $null) { $PageFile.Delete() } Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{name="$DL\pagefile.sys"; InitialSize = 0; MaximumSize = 0} ` -EnableAllPrivileges |Out-Null $PageFile = Get-WmiObject Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $DL'" $PageFile.InitialSize = $InitialSize $PageFile.MaximumSize = $MaximumSize [Void]$PageFile.Put() Write-Host "Execution Results: Set page file size on ""$DL"" successful." Write-Warning "Pagefile configuration changed on computer '$Env:COMPUTERNAME'. The computer must be restarted for the changes to take effect." } Catch { Write-Host "Execution Results: No Permission - Failed to set page file size on ""$DL""" }
Windows PowerShell 2.0
Additional Resources
Related forum threads:
http://social.technet.microsoft.com/Forums/en-US/mdt/thread/82fd5a8c-4a6f-4855-95c7-965f5b45c95c/
http://www.msfn.org/board/topic/46809-adjust-virtual-memory/
http://www.winvistatips.com/script-change-virtual-memory-settings-t754165.html