# PowerShell Script to set the size of pagefile.sys
$computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges;
$computersys.AutomaticManagedPagefile = $False;
$computersys.Put();
$pagefile = Get-WmiObject -Query "Select * From Win32_PageFileSetting Where Name like '%pagefile.sys'";
$pagefile.InitialSize = <New_Value_For_Size_In_MB>;
$pagefile.MaximumSize = <New_Value_For_Size_In_MB>;
$pagefile.Put();
Function Get-PageFileInfo {
<#
.Synopsis
Returns info about the page file size of a Windows computer. Defaults to local machine.
.Description
Returns the pagefile size info in MB. Also returns the PageFilePath, PageFileTotalSize, PagefileCurrentUsage,
and PageFilePeakusage. Also returns if computer is using a TempPafeFile and if the machine's pagefile is
managed by O/S (AutoManaged = true) or statically set (AutoManaged = False)
.Example
Get-PageFileInfo -computername SRV01
Returns pagefile info for the computer named SRV01
Computer : SRV01
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 60
PeakUsage (in MB) : 203
TempPageFileInUse : False
.Example
Get-PageFileInfo SRV01, SRV02
Returns pagefile info for two computers named SRV01 & DC02.
Computer : SRV01
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 60
PeakUsage (in MB) : 203
TempPageFileInUse : False
Computer : SRV02
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 0
PeakUsage (in MB) : 0
TempPageFileInUse : False
.Example
Get-PageFileInfo SRV01, SRV02, SRV03 | Format-Table
Returns pagefile info for three computers named SRV01, SRV02 & SRV03 in a table format.
Computer FilePath AutoManagedPageFile TotalSize (in MB) CurrentUsage (in MB) PeakUsage (in MB) TempPageFileInUse
-------- -------- ------------------- ----------------- -------------------- ----------------- -----------------
SRV01 C:\pagefile.sys True 8192 60 203 False
SRV02 C:\pagefile.sys True 13312 0 0 False
SRV03 C:\pagefile.sys True 2432 0 0 False
.Parameter computername
The name of the computer to query. Required field.
.Notes
NAME: Get-PageFileInfo
AUTHOR: Mike Kanakos
Version: v1.1
LASTEDIT: Thursday, August 30, 2018 2:19:18 PM
.Link
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[string[]]$ComputerName
)
# Main Part of function
Foreach ($computer in $ComputerName)
{
$online= Test-Connection -ComputerName $computer -Count 2 -Quiet
if ($online -eq $true)
{
$PageFileResults = Get-CimInstance -Class Win32_PageFileUsage -ComputerName $Computer | Select-Object *
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
$PageFileStats = [PSCustomObject]@{
Computer = $computer
FilePath = $PageFileResults.Description
AutoManagedPageFile = $CompSysResults.AutomaticManagedPagefile
"TotalSize(in MB)" = $PageFileResults.AllocatedBaseSize
"CurrentUsage(in MB)" = $PageFileResults.CurrentUsage
"PeakUsage(in MB)" = $PageFileResults.PeakUsage
TempPageFileInUse = $PageFileResults.TempPageFile
} #END PSCUSTOMOBJECT
} #END IF
else
{
# Computer is not reachable!
Write-Host "Error: $computer not online" -Foreground white -BackgroundColor Red
} # END ELSE
$PageFileStats
} #END FOREACH
} #END FUNCTION
4条答案
按热度按时间jrcvhitl1#
下面是我们如何通过PowerShell更新pagefile.sys的大小:
执行如下脚本:
hgc7kmma2#
此处为解决方案这是将C VOL页面文件设置为16384MB,将静态和D VOL页面文件设置为系统管理:
d4so4syb3#
好吧,要使用Powershell获取页面文件,请使用我从Mike Kanakos那里获得的函数:“function-getpagefilessize.ps1”,由于某种原因,它 * 不 * 作为PS文件或PSM文件从配置文件中工作:
作者:迈克·卡纳科斯
但是***设置***页面文件会遇到各种各样的问题。比如,它会有真实的的bug。如果设置了,你可以更改它,如果没有,你必须先设置为系统管理,然后设置为一些东西,比如C上的16384/16384和D上的系统管理。我自己正在寻找答案,因为我需要这个,当我把它排序后(在我要做的其他脚本的长列表中),我会回到你身边...但是,ITMT,这个函数会有帮助。对这样的列表做一个ForEach:
或者您在伊势中加载函数,运行它以加载到内存中,然后从PS cmd手动查询每个服务器:
如果要求您使用FQDN,您将看到空白...如果您管理的是标准系统,该函数将为您提供用法,并告诉您是否必须设置静态大小:
q0qdq0h24#
对于较新版本的PowerShell:
从PowerShell 3.0开始,
Get-WmiObject
cmdlet已被Get-CimInstance
取代。**注意:**您需要管理员权限才能更改页面文件。