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-NullAfter 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