Solved

Reducing size of page file on Hyper-V 2012 core

Posted on 2015-01-14
11
604 Views
Last Modified: 2015-04-08
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
Comment
Question by:abhijitm00
11 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 40550207
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
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 40550255
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
 
LVL 38

Assisted Solution

by:Philip Elder
Philip Elder earned 500 total points
ID: 40550474
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
 

Author Comment

by:abhijitm00
ID: 40551940
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
 
LVL 38

Expert Comment

by:Philip Elder
ID: 40552034
Could you post a snip of the two commands being run including the error please?
0
Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

 

Author Comment

by:abhijitm00
ID: 40552181
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
 
LVL 38

Expert Comment

by:Philip Elder
ID: 40552201
Change SERVERNAME to your server's name. Sorry if that wasn't clear. :(
0
 

Author Comment

by:abhijitm00
ID: 40552205
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
 
LVL 38

Accepted Solution

by:
Philip Elder earned 500 total points
ID: 40552222
Swapfile SuccessWorking for me?
0
 
LVL 38

Expert Comment

by:Philip Elder
ID: 40552225
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
 

Author Comment

by:abhijitm00
ID: 40552300
No had it correct the first time "C:\pagefile.sys"
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article will review the basic installation and configuration for Windows Software Update Services (WSUS) in a Windows 2012 R2 environment.  WSUS is a Microsoft tool that allows administrators to manage and control updates to be approved and ins…
Why should I virtualize?  It’s a question that’s asked often enough.  My response is usually “Why SHOULDN’T you virtualize?”
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
In this Micro Tutorial viewers will learn how they can get their files copied out from their unbootable system without need to use recovery services. As an example non-bootable Windows 2012R2 installation is used which has boot problems.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now