none
Pagefile settings RRS feed

  • Question

  • I am automating the deployment of Windows Server/Hyper-V and have run into an issue with trying to modify the pagefile setting.  In my deployment, I am using a VHD with native boot.  Therefore, I copy host.vhdx to the physical drive and use bcdboot to create a boot entry.  This causes the host.vhdx file to have the drive letter C: on boot, and the physical disk has drive letter D: 

    Basically, what I need to be able to do is set pagefile settings for drive D:  Win32_PagefileSetting sees and allows me to set the min/max pagefile size on C:.  But it does not see D:  I can see D:\pagefile.sys with Win32_PagefileUsage, but that does not let me set any values.  If I go in through the GUI, I can set min/max on both C: and D:, but I have not been able to figure out how to see D: so I can set values via Win32_PagefileSetting.  I need to set D: because Windows is looking for pagefile.sys on this drive during the boot process before it has loaded host.vhdx.  Because it was automanaged, now that I turned off automanaged, I get a message every time I log in telling me that Windows has changed my pagefile settings.

    Here is the code that works fine for setting the value on C:  What I need is some way to set the values for D: before I reboot the system to have all the changes take effect, just like what would happen if I were using the GUI.  I just can't figure out how to get to D:  I don't think this would be an issue if I were not using native VHD boot.

    $computerSystem = Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
        $computerSystem.AutomaticManagedPagefile = $false
        $computerSystem.Put() | Out-Null
    $pageFileSetting = Get-WmiObject -Class Win32_PageFileSetting
        $pageFileSetting.InitialSize = 1024
        $pageFileSetting.MaximumSize = 4096
        $pageFileSetting.Put() | Out-Null
    
    After I use the GUI to set min/max for both C: and D: and reboot, I can then see both C:pagefile.sys and D:pagefile.sys with Win32_PagefileSetting.  So if I can use the GUI to do this, it seems like I should be able to use PowerShell/WMI, but I can't figure out what I need to do to get to D:


    . : | : . : | : . tim

    Monday, October 12, 2015 8:50 PM

Answers

  • I asked for suggestions over in the MDT forum, figuring the people who do lots more deployment related work might have an idea.  So far, they haven't come up with anything specific to which WMI to call, but one individual did make the suggestion to mung the registry entry on pagefiles. I'm not a fan of registry munging, but until I find anything else, that's what I went with. Basically, at the end of the unattend install I change the registry value of pagefiles to include a d:\pagefile.sys with an initial/max size. That takes care of the issue.

    Thanks for the thoughts and ideas.


    . : | : . : | : . tim

    Wednesday, October 14, 2015 10:29 PM

All replies

  • Hi,

    Have you tried setting the Name property to specifically point to D:?

    https://msdn.microsoft.com/en-us/library/aa394245%28v=vs.85%29.aspx


    Monday, October 12, 2015 11:06 PM
  • Unless you're going to make it better, don't re-invent the wheel: https://gallery.technet.microsoft.com/scriptcenter/Script-to-configure-e8d85fee



    Mike Crowley | MVP
    My Blog -- Baseline Technologies

    Tuesday, October 13, 2015 1:08 AM
  • Thanks, Mike.  I had reviewed that code, but it does not work in my situation.  It assumes the pre-existence of information that can be obtained from the Win32_PagefileSetting.  In my case, I cannot retrieve Win32_PagefileSetting for drive D: - which is a requirement for the referenced code to work.  I tried.


    . : | : . : | : . tim

    Tuesday, October 13, 2015 1:14 PM
  • When I perform a gwmi on Win32_PagefileSetting, it returns a single object for C:\\pagefile.sys.  I can explicitly Select * from name c:\\pagefile.sys, but since there is just the single object, when I try to specify d:\\pagefile.sys, it fails. 

    This is why I am asking for help.  It seems like I need to create a new object.  How do I create a new object within Win32_PagefileSetting with PowerShell?  I am not a .NET programmer.  I can generally take an example and mung it until it does what I need, but I have not yet found an example of how to do this.


    . : | : . : | : . tim

    Tuesday, October 13, 2015 1:22 PM
  • You will find that any pagefile set to "automatic" will not be visible and will not have any settings.  TO change this you will need t create a pagefile use Win32_Pagefile.createInstance()

    Try this:

    gwmi win32_computersystem|select AutomaticManagedPagefile

    If it is set to true you will have to change it.


    \_(ツ)_/

    Tuesday, October 13, 2015 4:26 PM
  • As shown in my original post, I am setting AutomaticManagedPagefile to false in order to allow managing the pagefiles.  Setting the value to false is working properly.  Then I set the min/max on the c:\\pagefile.sys without any problem.  The problem is that I can't figure out how to reference d:\\pagefile.sys to change its min/max.  Win32_PagefileSetting is not returning the setting for d:\\pagefile.sys.  I've even tried rebooting a couple times to see if something changes.  What remains consistent is that Windows thinks there is d:\\pagefile.sys.  I can see it in the GUI.  I can see it in Win32_PagefileUsage, but Win32_PagefileSetting does not return it.  I can set a min/max on d:\\pagefile.sys from within the GUI, but I can't figure out how to get at it from PowerShell to make the change.

    I think it has something to do with the fact that I am using a native boot VHD file.  When I perform the same instructions on a system that is booting directly from a hard disk, I have no problem because the physical drive is the drive containing the operating system.  Because I am booting from a VHD, it seems to be adding some complexity.  The GUI handles it, so I figure there have to be some sort of system calls that are doing this.  The only one I have found is Win32_PagefileSetting, but, as noted, it is not giving me access to d:\\pagefile.sys.

    One more (strange) thing that I again think native boot is the culprit.  Even though Win32_PagefileUsage is showing a d:\pagefile.sys, when I go into the GUI, drive D: is set to no pagefile.  So the first thing I have to do is select the radio button to Custom size and then enter min/max to get things to work without warning errors.  Then Win32_PagefileSetting will show both D: and C: page files.  But I haven't been able to figure out what to call to change D: from no pagefile to Custom size.


    . : | : . : | : . tim


    Tuesday, October 13, 2015 6:28 PM
  • look at your pagefile in the GUI.  If your new page file is set to "System Managed Size" then it will not be visible.

    I have been through this before on Windows 8.


    \_(ツ)_/

    Tuesday, October 13, 2015 6:36 PM
  • After I set AutomaticManagedPagefile (Win32_ComputerSystem) to false, neither pagefile listed in the GUI is set to System managed size (first step of my automated script).  The pagefile in the VHDX is c:\pagefile.sys and the pagefile on the physical disk is d:\pagefile.sys.  D:\pagefile is set to No paging file, even though Win32_PagefileUsage lists it as the pagefile in use at a size of 0, while the GUI is reporting that 13518 is allocated.  I then use Win32_PagefileSetting to set initial/max on C:\Pagefile, and the GUI shows that as Custom Size.

    I just tried a Set-WMIInstance on Win32_PagefileSetting to try to add d:\pagefile.sys with initial/max equal to 512/1024 , but it gives me a "value out of range" error.  Tried other values and get the same thing. So I tried the same thing on c:\pagefile.sys and got different errors.  First error was using the values that I previously set as the custom size, and I got an error saying "Object or property already exists".  I then tried with C:\pagefile2.sys, thinking it might try adding a second file, but I got an error "Provider does not support put extensions".

     So I go into the GUI and set an initial/max size on D:\pagefile.sys, reboot, and everything is fine.  At that point, Win32_PagefileUsage still shows D:\pagefile.sys as the active pagefile with 0 peak usage.  Now Win32_PagefileSetting shows both C: and D: page files with the settings I gave them.  Until I manually change the D: from No paging file to Custom size, Win32_PagefileSetting can't see it.  Maybe there is a different class than Win32_PagefileSetting that I need in order to change from No to Custom?

    . : | : . : | : . tim

    Tuesday, October 13, 2015 7:56 PM
  • Nope.  That is just the way WMI works.  If set to system WMI cannot see it.  There seems to be no way to change that in WMI.


    \_(ツ)_/

    Tuesday, October 13, 2015 8:26 PM
  • Set-WmiInstance-ClassWin32_PageFileSetting-Arguments@{Name=$Path; InitialSize = $InitialSize;MaximumSize = $MaximumSize}

    https://powerscripter.wordpress.com/2014/05/15/configure-windows-programmatically/

    This is supposed to work on 2012/win8


    \_(ツ)_/

    Tuesday, October 13, 2015 8:29 PM
  • That's the exact command I tried to use and got the errors.

    I hate to call 'bug', but there is something funky going on with the pagefile when using a native boot VHD.  Maybe I have something set up wrong there, but that seems pretty straightforward.  I use WinPE to format the local drive, copy the VHDX file to the local drive, run bcdboot to create the boot entry, and then exit WinPE.  System boots fine, but there is the pagefile on D: that I think Windows is forcing there because it is not finding one when it first accesses the system.  Then when the OS comes up from the VHDX, that instance recognizes the pagefile on C: but not the one on D:.  What is driving me crazy is that the GUI sees it, but I can't get at it with WMI.  Everything seems to work just fine if I am working with just physical disks.  It seems to go funky with the native VHD.


    . : | : . : | : . tim

    Tuesday, October 13, 2015 8:43 PM
  • I've spent some more time thinking and researching on this one.  Still no answer, but maybe someone with more WMI knowledge can help.

    I am guessing that the reason Win32_PagefileSetting is not allowing me to access D:\pagefile.sys is because D: is set to None - even though it is using it.  Since Win32_PagefileSetting is returning only entries that have a defined pagefile, maybe if I could set D: to Custom Size, I would then have the ability to set the pagefile initial/max values.

    Is there a WMI call that will change D: from None to either system managed or custom size?  After all, that seems to be what I am doing with the GUI.


    . : | : . : | : . tim

    Wednesday, October 14, 2015 7:20 PM
  • I asked for suggestions over in the MDT forum, figuring the people who do lots more deployment related work might have an idea.  So far, they haven't come up with anything specific to which WMI to call, but one individual did make the suggestion to mung the registry entry on pagefiles. I'm not a fan of registry munging, but until I find anything else, that's what I went with. Basically, at the end of the unattend install I change the registry value of pagefiles to include a d:\pagefile.sys with an initial/max size. That takes care of the issue.

    Thanks for the thoughts and ideas.


    . : | : . : | : . tim

    Wednesday, October 14, 2015 10:29 PM