我可以像这样通过WMI修改页面文件设置
PS D:\> gwmi win32_pagefilesetting MaximumSize Name Caption ----------- ---- ------- 8192 c:\pagefile.sys c:\ 'pagefile.sys' 8192 d:\pagefile.sys d:\ 'pagefile.sys' PS D:\> $pf=gwmi win32_pagefilesetting PS D:\> $pf.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array PS D:\> $pf[0].InitialSize=4096;$pf[0].MaximumSize=4096 PS D:\> $pf[0].Put() PS D:\> gwmi win32_pagefilesetting MaximumSize Name Caption ----------- ---- ------- 4096 c:\pagefile.sys c:\ 'pagefile.sys' 8192 d:\pagefile.sys d:\ 'pagefile.sys'
但是我怎样才能删除一个页面文件的设置,例如在这个删除页面文件的D:?
find了。
有一个.Delete()方法来完成这个技巧。
PS D:\> $pf[1].Delete() PS D:\> gwmi win32_pagefilesetting MaximumSize Name Caption ----------- ---- ------- 4096 c:\pagefile.sys c:\ 'pagefile.sys'
完成。
尽pipe不被某些人推荐,但如果您想完全禁用页面文件,请确保也禁用自动页面pipe理:
# Disable automatic pagefile management $cs = gwmi Win32_ComputerSystem if ($cs.AutomaticManagedPagefile) { $cs.AutomaticManagedPagefile = $False $cs.Put() } # Disable a *single* pagefile if any $pg = gwmi win32_pagefilesetting if ($pg) { $pg.Delete() }