-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFullSystemMaintenance.ps1
More file actions
161 lines (136 loc) · 6.43 KB
/
Copy pathFullSystemMaintenance.ps1
File metadata and controls
161 lines (136 loc) · 6.43 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# ==========================================
# WINDOWS 11 WEEKEND MAINTENANCE SCRIPT
# Runs ONLY Wednesday & Sunday
# ==========================================
# -------------------------------
# CHECK DAY (Wednesday or Sunday)
# -------------------------------
$today = (Get-Date).DayOfWeek
if ($today -ne "Wednesday" -and $today -ne "Sunday") {
Write-Host "This script only runs on Wednesday and Sunday."
Exit
}
# -------------------------------
# ENSURE ADMIN
# -------------------------------
If (-NOT ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Host "Please run as Administrator!" -ForegroundColor Red
Exit
}
Write-Host "Starting Wednesday/Sunday System Maintenance..." -ForegroundColor Cyan
# -------------------------------
# BROWSER PROCESS LIST
# -------------------------------
$browserProcesses = "chrome","msedge","firefox","iexplore"
# -------------------------------
# OPEN BROWSERS (Triggers Extension Updates)
# -------------------------------
Start-Process "chrome.exe" -ErrorAction SilentlyContinue
Start-Process "msedge.exe" -ErrorAction SilentlyContinue
Start-Process "firefox.exe" -ErrorAction SilentlyContinue
Start-Process "iexplore.exe" -ErrorAction SilentlyContinue
Start-Sleep -Seconds 20
# -------------------------------
# FORCE BROWSER UPDATE CHECK
# -------------------------------
Start-Process "chrome.exe" "--check-for-update-interval=1" -ErrorAction SilentlyContinue
Start-Process "msedge.exe" "--check-for-update-interval=1" -ErrorAction SilentlyContinue
Start-Sleep -Seconds 10
# -------------------------------
# CLOSE ALL BROWSERS
# -------------------------------
foreach ($proc in $browserProcesses) {
Get-Process $proc -ErrorAction SilentlyContinue | Stop-Process -Force
}
Start-Sleep -Seconds 5
# -------------------------------
# CLEAR GOOGLE CHROME DATA
# -------------------------------
Write-Host "Clearing Chrome Data..."
$chromePath = "$env:LOCALAPPDATA\Google\Chrome\User Data"
if (Test-Path $chromePath) {
Get-ChildItem $chromePath -Directory | ForEach-Object {
Remove-Item "$($_.FullName)\History" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Cookies" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Cache\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Web Data" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\DownloadMetadata" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Extension State\*" -Recurse -Force -ErrorAction SilentlyContinue
}
}
# -------------------------------
# CLEAR MICROSOFT EDGE DATA
# -------------------------------
Write-Host "Clearing Edge Data..."
$edgePath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data"
if (Test-Path $edgePath) {
Get-ChildItem $edgePath -Directory | ForEach-Object {
Remove-Item "$($_.FullName)\History" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Cookies" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Cache\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Web Data" -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\DownloadMetadata" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($_.FullName)\Extension State\*" -Recurse -Force -ErrorAction SilentlyContinue
}
}
# -------------------------------
# CLEAR FIREFOX DATA
# -------------------------------
Write-Host "Clearing Firefox Data..."
$firefoxProfiles = Get-ChildItem "$env:APPDATA\Mozilla\Firefox\Profiles\" -Directory -ErrorAction SilentlyContinue
foreach ($profile in $firefoxProfiles) {
Remove-Item "$($profile.FullName)\places.sqlite" -Force -ErrorAction SilentlyContinue
Remove-Item "$($profile.FullName)\cookies.sqlite" -Force -ErrorAction SilentlyContinue
Remove-Item "$($profile.FullName)\cache2\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($profile.FullName)\storage\default\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$($profile.FullName)\extension-settings.json" -Force -ErrorAction SilentlyContinue
}
# -------------------------------
# CLEAR INTERNET EXPLORER DATA
# (Deprecated in Windows 11)
# -------------------------------
Write-Host "Clearing Internet Explorer Data..."
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255
# -------------------------------
# WINDOWS UPDATE (ALL TYPES)
# -------------------------------
Write-Host "Running Windows Update..."
Install-Module PSWindowsUpdate -Force -Confirm:$false -ErrorAction SilentlyContinue
Import-Module PSWindowsUpdate -ErrorAction SilentlyContinue
Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -IgnoreReboot -ErrorAction SilentlyContinue
# Backup & Cleanup Windows Update Components
Dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase
# -------------------------------
# MICROSOFT STORE UPDATES
# -------------------------------
Write-Host "Updating Microsoft Store Apps..."
Get-CimInstance -Namespace "Root\cimv2\mdm\dmmap" `
-ClassName "MDM_EnterpriseModernAppManagement_AppManagement01" -ErrorAction SilentlyContinue |
Invoke-CimMethod -MethodName UpdateScanMethod -ErrorAction SilentlyContinue
# -------------------------------
# WINDOWS SECURITY INTELLIGENCE UPDATE
# -------------------------------
Write-Host "Updating Security Intelligence..."
Update-MpSignature -ErrorAction SilentlyContinue
# -------------------------------
# DELETE TEMP FILES
# -------------------------------
Write-Host "Deleting TEMP files..."
Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# Delete Windows Error Reports
Remove-Item "C:\ProgramData\Microsoft\Windows\WER\*" -Recurse -Force -ErrorAction SilentlyContinue
# -------------------------------
# EMPTY RECYCLE BIN
# -------------------------------
Write-Host "Emptying Recycle Bin..."
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
# -------------------------------
# SYSTEM CLEANUP (Storage Equivalent)
# -------------------------------
Write-Host "Running System Cleanup..."
cleanmgr /verylowdisk
Write-Host "Wednesday/Sunday Maintenance Complete!" -ForegroundColor Green