Files
general-scripts-and-system-…/Windows-Scripts/windows-repair.ps1
T
2026-06-13 02:36:49 -06:00

148 lines
9.5 KiB
PowerShell

# Usage:
# Open PowerShell as Administrator
# win+x
# alt+a
# alt+y
# Run:
# In admin powershell Terminal:
# iwr https://git.thecoven.info/PrincessPi/general-scripts-and-system-ssssssetup/raw/branch/main/Windows-Scripts/windows-repair.ps1?nocache=$(Get-Random) -OutFile $env:TEMP\windows-repair-temp.ps1; powershell -NoProfile -ep Bypass -File $env:TEMP\windows-repair-temp.ps1
# check if hasadmin rights, if notm run script in new terminal, clopsing old
## if not, carry on
if (-not ([Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544')) {
# launch tghis script int new window after promopting for admin
Start-Process -FilePath 'powershell' -Verb RunAs -ArgumentList "-ExecutionPolicy Bypass -File $PSCommandPath"
# CLOSE previous terminal
exit 0
} else {
Clear-Host # clear window
Write-Host -ForegroundColor Magenta @'
.. .....
....------..
..:--------.. .......
..----------.. ....---..
...---------=------::....:----:..
..-----=+**************=-----:...
.----+****************=-----...
.--=****************=-----=**+:::--:....
.-=#*********##**++=---====++**+-----:.
..:==********#=.+@%-==++===++===++*=----...
.:=::******%%+-::=++====+==++====+**=--...
.:+..+*****--@===-:-%--====-=+====+*#=:..
.-=.-****#=.#+===--=+===----======+*+..
.:=:+****#@#+=====-**-----*+====++**:.
.. .=****=--======-..%-----%+==++***+-..
..=++***+-.----======..*-----#+==+***#%#+..
.. .:-..---=====--------=-+==+**-@*. ............::::::....
..=:..--===+-:-------*%+==*+#%**=. .....:-------------------------:.
..............-:..--===+-..:-------+==+==.:... ...:----------------------------::.
......:----------::=:...--==+--:.:-------+==+=:.... ....--------------------------:.....
..:::----------------=-::.:--===---:.:------=--:.... ...:---------------------------...
..:------------------=--:..:--=+=--------::.:+-..... ...------------------------------..
...:-----------------:....----==-------:...=%*.......:::--------------------------------:..
...--------------:+......---------------:+%%#.----------------------------:.......-----:..
.:----===-------:-.. .:--------------*%%%%=--------------========------:.......-------:...
..-:.:------------....-.=---------=#%%%%##%------------=-----------------------------------..
.:--:....:--------:##*=:.-------=#%%%%%%#%+-----------=-------------------------------------:
..:-----------------::*%%#-------=###%%%%##=--------------------------------------:............
..:-------------------:.-#%%##+==+%%%%%%#%+------------------------...:::--------------::::::..
...:----------------------..-#%#%%%%%%%%*+#%=-------------------------=-:....:----------------:...
--------------------------:.-#%%%%%%%%+#@%%%--------------------------=++=-::---------------:...
---------------------------...+%%%%%%%#%%%%#---------------------------------------------:....
............------.....----:....-#%%%%%%%*=------------------------------::+=---------.......
..:-... ....-----.. ....-=-------------------------------------.=*+=.......
..---:....:-----:.......:--------------------------:-------------==+=-......
.:-------------..........:---------------------------..:-------------==..........
..-------------:... ...--------:...----------------....:-----------==-...........
..:----==------:..-.... ..--------:...:---------------.....:----------=+-.....
..------==+=++==-..+--:. .:--------.....-----------=*%=.. ..----------=+=......
....------------........:... ..:--------.....-------+#%%#@%.. ...----------=+=......
....---------===:............... .:----=+*#=. ..--+#**+%@@@#%+. ..:-:..=----=*=:.....
:............:=::+=:--:=.=-.::=... ..*@*-+%@@@:.....-@@#%@*#@@@#%:.. ..-:..---:-#**+-.........
.. ...::::....::-.:.::-.. ..*%:..*@@@*.. ..-%#%@@+%@@@@=.. ...::.=#=..-%*++=:... ...
...... .......... ..**...*#=*%:. .-*#@%+#%@@@@+... ..*%@%+...+%+=*+=-...
..*#:.-#+..+-. ..-*#**%%*%@@%=.. ..-%@@*:..+@%=:+**+=:..
..*@#*%%=..==. .-*%@#%@##@@@#-. ...#@@%*-=%@@#:..-=++=-
.:#@*-:++..==. .=#%@%*@@*%*=+*:....:.+@*::+%@@@%=......-*
.-%+...=%##%-. .+@*@%*%@##*-:*+..:-==*@=..:#@+:=*:.......
.:*#:..:*@@@%:. .-%@*%@#*%*#=..-%-....:+#=-.:#%-.:+-.......
.+@#=.-*@@@@*.. ....-%@@@@@@=..+%*.. .-%--=+#%-.:*-. ....
.-=++++++++=... .:***+++==::::... .-%#=-*#%#**#-.
..............
'@
Write-Host "FIXING WINDOWS FULL PRINCESS PI STYLE (THIS WILL TAKE MANY HOURS AND REBOOT MORE THAN ONCE, SLOWLY)`n" -ForegroundColor Magenta
$LogDir = "$env:USERPROFILE\Downloads\Repair-Log-$((Get-Date).ToString('yyyy-MM-dd-HHmm'))" # path to new log Dir
$ErrorLog = "$LogDir\error.log" # error log file
Write-Host "Creating Log Dir at $LogDir 1/20"
New-Item -Path "$LogDir" -ItemType Directory > $null 2>> $null # create log dir
Write-Host "Initialize Log File $LogFile 2/20"
Write-Host "$((Get-Date).ToString('yyyy-MM-dd-HHmm'))" 2>> "$ErrorLog"
Write-Host "ABORTING ANY SCHEDULED SHUTDOWN 3/20"
shutdown.exe /a > $null 2>> "$ErrorLog" # cmd abort scheduled shutdowns
Write-Host "Creating Log Dir at $LogDir 4/20"
New-Item -Path "$LogDir" -ItemType Directory > $null 2>> "$ErrorLog" # create log dir
Write-Host "GENERATING AND DISPLAYING COMPREHENSIVE STABILITY REPORT 5/20"
Start-Process "perfmon.exe" -ArgumentList "/report" -Wait # running report
Write-Host "GENERATING AND DISPLAYING STABILITY HISTORY REPORT 6/20"
Start-Process "perfmon.exe" -ArgumentList "/rel" -Wait # historical report
Write-Host "CLEARING DNS 7/20"
ipconfig.exe /flushsdns > $null 2>> "$ErrorLog" # flush dns cache
Write-Host "CLEARING ARP CACHE 8/20"
Remove-NetNeighbor -Confirm:$false > $null 2>> "$ErrorLog" # flush ARP Table
Write-Host "CLEARING ALL SAMBA CREDENTIALS 9/20"
net.exe use * /delete /y > $null 2>> "$ErrorLog" # nuke all samba creds automagically
Write-Host "RELEASING AND RENEWING DHCP 10/20"
# release and renew dhcp
ipconfig.exe /release > $null 2>> "$ErrorLog"
ipconfig.exe /renew > $null 2>> "$ErrorLog"
Write-Host "GETTING CONTROL OF WINDOWS UPDATE 11/20"
Install-Module -Name PSWindowsUpdate -Force > $null 2>> "$ErrorLog"
Import-Module PSWindowsUpdate
Write-Host "UPDATING WINDOWS 12/20"
Get-WindowsUpdate -AcceptAll -Install -IgnoreReboot > $null 2>> "$ErrorLog"
Write-Host "UPDATING MALWARE SIGNATURES 13/20"
Update-MpSignature 2>> "$ErrorLog" # update windows defender malware siggs
Write-Host "RUNNING FULL WINDOWS DEFENDER SCAN 14/20"
Start-MpScan -ScanType FullScan 2>> "$ErrorLog" # full windows defender scan
Write-Host "RUNNING DISM ONLINE IMAGE CLEANUP 15/20"
DISM.exe /Online /Cleanup-Image /RestoreHealth 2>> "$ErrorLog" # online check for bad files
Write-Host "RUNNING SYSTEM FILE CHECKER (SFC) 16/20"
SFC.exe /scannow 2>> "$ErrorLog" # older check for bad files
Write-Host "SCHEDULING ESSENTIAL FILE CHECK ON NEXT BOOT 17/20"
SFC.exe /scanonce 2>> "$ErrorLog" # check essential files on next boot
Write-Host "SCHEDULING OFFLINE CHECK DISK AND REPAIR OF C: (CHKDSK) 18/20"
echo y | chkdsk.exe /f /r C: > $null 2>> "$ErrorLog" # cmd checks C drive after reboot to waste time and fix errors (noninteractive via y ffuckery)
Write-Host "SCHEDULINMG OFFLINE MEMTEST 19/20"
mdsched.exe /s 2>> "$ErrorLog" # schedule offline memtest (noninteractive)
Write-Host "SCHEDULING WINDOWS DEFENDER OFFLINE SCAN MAY REBOOT UNEXPECTEDLY 20/20"
Start-MpWDOScan 2>> "$ErrorLog" # powershell starts Windows Defender Offline Scan after reboot
Write-Host "`nREBOOTING IN 5 MINUTES MAX PROVBABLY SOONER`n"
shutdown.exe /r /t (60*5) # shutdown in 5 minutes as failsafe
Write-Host "`nDONEsiez :3~`n"
}