-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSDOptimizations.ps1
98 lines (54 loc) · 1.85 KB
/
SSDOptimizations.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright (c) 2019 Gurjit Singh
# This source code is licensed under the MIT license that can be found in
# the accompanying LICENSE file or at https://opensource.org/licenses/MIT.
# Imports
try {
# Catch All Errors
$ErrorActionPreference = "Stop"
Import-Module -Force $PSScriptRoot\Import\Get-AnyKeyTo.psm1
Import-Module -Force $PSScriptRoot\Import\Get-Admin.psm1
Import-Module -Force $PSScriptRoot\Import\Set-ScriptStartEnd.psm1
}
catch {
Write-Output ("n`nError Details: `n$($PSItem.Exception)`n" +
"`n$($PSItem.CategoryInfo)`n")
Exit
}
finally {
# Clear Flags
$ErrorActionPreference = "Continue"
}
# Global Vars
$Title = "SSD Optimizations"
$LogFile = "Log.txt"
# Elevate privileges
Get-Admin
# Tucked away Boilerplate code
Set-ScriptStart -Title $Title -LogFile $LogFile
### Start Here
# Optimize Page File
$sys = Get-WmiObject Win32_Computersystem –EnableAllPrivileges
$sys.AutomaticManagedPagefile = $false
$sys.put()
$pageFile = Get-WmiObject Win32_PagefileSetting | Where-Object { $_.name -eq "%SYSTEMDRIVE%\pagefile.sys" }
$pageFile.InitialSize = 512 # in MB
$pageFile.MaximumSize = 2048 # in MB
$pageFile.put()
Get-WmiObject WIN32_Pagefile | Select-Object Name, InitialSize, MaximumSize, FileSize
# Optimize Event Logs
$Logs = Get-EventLog -List | select -ExpandProperty Log
foreach ($Log in $Logs) {
Limit-EventLog -LogName $Log -MaximumSize 20Mb -OverflowAction OverwriteAsNeeded
}
$failureOnly = @("System Integrity", "Other System Events")
foreach ($name in $failureOnly) {
auditpol /set /subcategory:$name /success:disable /failure:enable
}
$disable = @("Filtering Platform Connection", "Network Policy Server")
foreach ($name in $disable) {
auditpol /set /subcategory:$name /success:disable /failure:disable
}
### End Here
# Tucked away Boilerplate code
Set-ScriptEnd