-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixWindowsSystem.ps1
More file actions
159 lines (115 loc) · 6.09 KB
/
FixWindowsSystem.ps1
File metadata and controls
159 lines (115 loc) · 6.09 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
# Fix Windows System by 0xNixxy
# Repo: https://github.com/0xNixxy/fix-windows-system
# This script needs Windows PowerShell Administrator to execute.
# ==============================================================================
# MIT License
#
# Copyright (c) 2025-2026 Nicholas Ho
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ==============================================================================
# ==============================================================================
# TROUBLESHOOTING NOTE
# If you have problems executing PowerShell scripts on your local machine, you
# may need to first perform a one-time relaxing of PowerShell Execution Policy
# with "Set-ExecutionPolicy -ExecutionPolicy Bypass" in PowerShell(Admin).
# You can check your current policy with "Get-ExecutionPolicy -List"
# ==============================================================================
# Script Pre-requisites
#Requires -Version 5.1 # Minimum version 5.1
# Check for Admin rights
# If not in Admin Powershell, automatically re-launch in Admin Powershell
$currID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$currPrincipal = New-Object System.Security.Principal.WindowsPrincipal(${currID})
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
if(-not $currPrincipal.IsInRole(${adminRole}))
{
Write-Warning -Message "[INFO] This script requires administrative privileges."
Write-Warning -Message "[INFO] Re-launching script in PowerShell (Admin)."
$adminPowerShellArgs = "-ExecutionPolicy Bypass -File `"$PSCommandPath`""
Start-Process powershell.exe -Verb RunAs -ArgumentList $adminPowerShellArgs
# Exit current non-admin PowerShell session
exit
}
# Add blank lines to avoid script text output from being obscured by progress
# pop-ups by Repair-WindowsImage and Repair-Volume.
Write-Output -InputObject ""
Write-Output -InputObject ""
Write-Output -InputObject ""
Write-Output -InputObject ""
Write-Output -InputObject ""
Write-Output -InputObject ""
Write-Output -InputObject ""
# Show program name and version
Write-Output -InputObject ""
Write-Output -InputObject "------------------------------------"
Write-Output -InputObject "Fix Windows System v1.2.0 by 0xNixxy"
Write-Output -InputObject "------------------------------------"
Write-Output -InputObject ""
# Remove unused driver packages in Windows
Write-Output -InputObject "[INFO] Clean up unused drivers in Windows system..."
& rundll32.exe pnpclean.dll,RunDLL_PnpClean /DRIVERS /MAXCLEAN
Write-Output -InputObject ""
# Detect and repair errors found in Windows component store (WinSxS)
Write-Output -InputObject "[INFO] Quick status check on Windows component store health..."
Repair-WindowsImage -Online -CheckHealth
Write-Output -InputObject ""
Write-Output -InputObject "[INFO] Scan Windows component store and automatically fix issues..."
Repair-WindowsImage -Online -RestoreHealth
Write-Output -InputObject ""
# Detect and repair errors found in Windows system files
# As SFC uses Windows image as a baseline to repair corrupted system files,
# run SFC only after DISM verified that Windows image is healthy. I found that
# adopting a trivial approach to run SFC twice per run seems sufficient to
# resolve all file system issues for virtually all users. In the rare scenario
# that two SFC runs is unable to fix all issues, the user just needs to
# execute "SFC /scannow" manually after the script has completed.
Write-Output -InputObject "[INFO] Check Windows system files and automatically fix issues..."
Write-Output -InputObject "[INFO] Run 1 of 2."
& sfc.exe /scannow
Write-Output -InputObject ""
Write-Output -InputObject "[INFO] Run 2 of 2."
& sfc.exe /scannow
Write-Output -InputObject ""
# Remove superseded versions of updated components in Windows component store
Write-Output -InputObject "[INFO] Clean up unused components in Windows component store..."
Repair-WindowsImage -Online -StartComponentCleanup
Write-Output -InputObject ""
# Detect and repair errors found in disk volume
# Check for errors, and invoke offline repairs if errors detected,
# otherwise proceed to defrag/trim disk drive.
Write-Output -InputObject "[INFO] Checking disk volume..."
if ((Repair-Volume -DriveLetter C -Scan).value__ -eq 0)
{
Write-Output -InputObject ""
Write-Output -InputObject "[INFO] No issues found. Disk volume is healthy."
Write-Output -InputObject ""
Write-Output -InputObject "[INFO] Optimise disk I/O performance and storage efficiency...."
Optimize-Volume -DriveLetter C -Verbose
Write-Output -InputObject "[INFO] Disk volume optimisation complete."
Read-Host "Press Enter to continue..."
}
else
{
Write-Output -InputObject ""
Write-Warning -Message "[WARNING] !! Errors found in disk volume."
Write-Output -InputObject "[INFO] Taking disk volume offline for repairs..."
Read-Host "Press Enter to continue..."
Repair-Volume -DriveLetter C -OfflineScanAndFix
}