-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.ps1
48 lines (43 loc) · 1.12 KB
/
page.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PARAM(
[string]$Path,
[int]$InitialSize,
[int]$MaximumSize
)
$ComputerSystem = $null
$CurrentPageFile = $null
$modify = $false
# Disables automatically managed page file setting first
$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
if ($ComputerSystem.AutomaticManagedPagefile)
{
$ComputerSystem.AutomaticManagedPagefile = $false
$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
$modify = $true
}
if ($CurrentPageFile.MaximumSize -ne $MaximumSize)
{
$CurrentPageFile.MaximumSize = $MaximumSize
$modify = $true
}
if ($modify)
{
$CurrentPageFile.Put()
}
}
else
{
# Creates a new page file
if ($CurrentPageFile -ne $null)
{
$CurrentPageFile.Delete()
}
Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{ Name = $Path; InitialSize = $InitialSize; MaximumSize = $MaximumSize }
}