-
Notifications
You must be signed in to change notification settings - Fork 0
/
Old-Script.ps1
61 lines (48 loc) · 2.34 KB
/
Old-Script.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
# Change PowerShell background color to Black
$originalBgColor = $Host.UI.RawUI.BackgroundColor
$Host.UI.RawUI.BackgroundColor = "Black"
Clear-Host # Refresh the console with the new background color
# Check for administrative privileges
$isAdmin = [bool]((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
if (-not $isAdmin) {
Write-Host "This script requires administrative privileges." -ForegroundColor Red
Write-Host "Please run it as an administrator." -ForegroundColor Yellow
Write-Host ""
Read-Host "Press Enter to exit..." -ForegroundColor Gray
exit 1
}
Start-Sleep -Milliseconds 500
# Resetting Windows Update Components
Write-Host "Resetting Windows Update Components..." -ForegroundColor Green
Start-Sleep -Milliseconds 500
# Stop Windows Update service (wuauserv) and BITS service
Stop-Service -Name wuauserv -Force
Stop-Service -Name bits -Force
# Delete files in SoftwareDistribution
Remove-Item -Path "C:\Windows\SoftwareDistribution\*" -Force -Recurse
# Start Windows Update service (wuauserv) and BITS service
Start-Service -Name wuauserv
Start-Service -Name bits
Start-Sleep -Milliseconds 500
# Repair the Windows image by downloading replacement files from Windows Update.
Write-Host "Repairing the Windows image..." -ForegroundColor Blue
Start-Sleep -Milliseconds 500
DISM /Online /Cleanup-Image /RestoreHealth
# Clean up the component store to reduce the size of the WinSxS folder.
Write-Host "Cleaning up the component store..." -ForegroundColor DarkCyan
Start-Sleep -Milliseconds 500
DISM /Online /Cleanup-Image /StartComponentCleanup
# Scan and repair corrupted or missing system files.
Write-Host "Scanning and repairing corrupted or missing system files..." -ForegroundColor Cyan
Start-Sleep -Milliseconds 500
sfc /scannow
# Scan and repair file system errors and bad sectors on an external drive with the drive letter "C:"
Write-Host "Scanning and repairing file system errors on drive C:..." -ForegroundColor Yellow
Start-Sleep -Milliseconds 500
echo Y | chkdsk /f /r C:
Write-Host ""
Write-Host "Maintenance completed. Please restart the computer" -ForegroundColor Green
Read-Host "Press Enter to exit..."
# Revert PowerShell background color to original
$Host.UI.RawUI.BackgroundColor = $originalBgColor
Clear-Host