[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 888
  • Last Modified:

Reducing size of page file on Hyper-V 2012 core

Hi Experts, need to reduce page file size on Hyper-V hosts in a cluster. Have moved all VMs to one host and trying to run the following which completes successfully:

PS C:\> wmic computersystem set AutomaticManagedPagefile=false
Updating property(s) of '\\VMHOST\ROOT\CIMV2:Win32_ComputerSystem.Name="VMHOST"'
Property(s) update successful.

But when I try to run the following I get the error message below:
PS C:\> wmic pagefileset where name=”C:\\pagefile.sys” set InitialSize=1024,MaximumSize=3096
Invalid format.
Hint: <assignlist> = <propertyname>=<propertyvalue> [, <assignlist>].

Am running in powershell from console as Administrator. Thanks
0
abhijitm00
Asked:
abhijitm00
2 Solutions
 
David Johnson, CD, MVPOwnerCommented:
found this http://bit.ly/1IywMOa
function Set-PageFile
{
    <#
    .SYNOPSIS
        Sets Page File to custom size
 
    .DESCRIPTION
        Applies the given values for initial and maximum page file size.
 
    .PARAMETER Path
        The page file's fully qualified file name (such as C:\pagefile.sys)
 
    .PARAMETER InitialSize
        The page file's initial size [MB]
 
    .PARAMETER MaximumSize
        The page file's maximum size [MB]
 
    .EXAMPLE
        C:\PS> Set-PageFile "C:\pagefile.sys" 4096 6144
    #>
 
    [CmdletBinding(SupportsShouldProcess=$True)]
    param (
        [Parameter(Mandatory=$true,Position=0)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Path,
        [Parameter(Mandatory=$true,Position=1)]
        [ValidateNotNullOrEmpty()]
        [Int]
        $InitialSize,
        [Parameter(Mandatory=$true,Position=2)]
        [ValidateNotNullOrEmpty()]
        [Int]
        $MaximumSize
    )
     
    Set-PSDebug -Strict
 
    $ComputerSystem = $null
    $CurrentPageFile = $null
    $Modified = $false
 
    # Disables automatically managed page file setting first
    $ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
    if ($ComputerSystem.AutomaticManagedPagefile)
    {
        $ComputerSystem.AutomaticManagedPagefile = $false
        if ($PSCmdlet.ShouldProcess("$($ComputerSystem.Path.Server)", "Disable automatic managed page file"))
        {
            $ComputerSystem.Put()
        }
    }
 
    $CurrentPageFile = Get-WmiObject -Class Win32_PageFileSetting
    if ($CurrentPageFile.Name -eq $Path)
    {
        # Keeps the existing page file
        if ($CurrentPageFile.InitialSize -ne $InitialSize)
        {
            $CurrentPageFile.InitialSize = $InitialSize
            $Modified = $true
        }
        if ($CurrentPageFile.MaximumSize -ne $MaximumSize)
        {
            $CurrentPageFile.MaximumSize = $MaximumSize
            $Modified = $true
        }
        if ($Modified)
        {
            if ($PSCmdlet.ShouldProcess("Page file $Path", "Set initial size to $InitialSize and maximum size to $MaximumSize"))
            {
                $CurrentPageFile.Put()
            }
        }
    }
    else
    {
        # Creates a new page file
        if ($PSCmdlet.ShouldProcess("Page file $($CurrentPageFile.Name)", "Delete old page file"))
        {
            $CurrentPageFile.Delete()
        }
        if ($PSCmdlet.ShouldProcess("Page file $Path", "Set initial size to $InitialSize and maximum size to $MaximumSize"))
        {
            Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{Name=$Path; InitialSize = $InitialSize; MaximumSize = $MaximumSize}
        }
    }
}

Open in new window

0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
On Hyper-V Server, you should leave the pagefile set to system managed.

Reference: http://www.aidanfinn.com/?p=15659
That said, you should also review the Technet blog on the subject of Pagefile size for Hyper-V guests and hosts:
http://blogs.technet.com/b/mghazai/archive/2011/05/26/what-s-the-story-of-pagefile-size-on-hyper-v-servers.aspx

Finally, if you still want to set it manually, try running the WMIC in a command prompt and NOT in a POWERSHELL prompt.
0
 
Philip ElderTechnical Architect - HA/Compute/StorageCommented:
We set all Hyper-V servers whether standalone or clustered to 4192MB Min/Max.

wmic.exe computersystem where name="SERVERNAME" set AutomaticManagedPagefile=False
wmic.exe pagefileset where name="c:\\pagefile.sys" set InitialSize=4199,MaximumSize=4199
1.      Reboot
2.      Dir /as in C:\
      Swap File should be 4GB.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
abhijitm00Author Commented:
Thanks for replying.

Philip, on trying your commands the first command worked. Running the second I get:
ERROR:
Description = Value out of range

I have tried changing values for initial and maximum size but still get the same error
0
 
Philip ElderTechnical Architect - HA/Compute/StorageCommented:
Could you post a snip of the two commands being run including the error please?
0
 
abhijitm00Author Commented:
C:\Users\>wmic.exe computersystem where name="SERVERNAME" set Automat
icManagedPagefile=False
Updating property(s) of '\\VMHOST\ROOT\CIMV2:Win32_ComputerSystem.Name="VMHOST"
Property(s) update successful.

C:\Users\>wmic.exe pagefileset where name="c:\\pagefile.sys" set InitialSize=4192,MaximumSize=8092
Updating property(s) of '\\VMHOST\ROOT\CIMV2:Win32_PageFileSetting.Name="C:\\pagefile.sys"'
ERROR:
Description = Value out of range
0
 
Philip ElderTechnical Architect - HA/Compute/StorageCommented:
Change SERVERNAME to your server's name. Sorry if that wasn't clear. :(
0
 
abhijitm00Author Commented:
Sorry you were quite clear and that command did work as below:

C:\Users\>wmic.exe computersystem where name="VMHOST" set AutomaticManagedPagefile=False
Updating property(s) of '\\VMHOST\ROOT\CIMV2:Win32_ComputerSystem.Name="VMHOST"'
Property(s) update successful.
0
 
Philip ElderTechnical Architect - HA/Compute/StorageCommented:
Swapfile SuccessWorking for me?
0
 
Philip ElderTechnical Architect - HA/Compute/StorageCommented:
Something just tweaked in the grey matter. The "C:\\Pagefile.sys" may need caps as I have it here or just one or the other capitalized.
0
 
abhijitm00Author Commented:
No had it correct the first time "C:\pagefile.sys"
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now