-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows fixer.ps1
More file actions
601 lines (525 loc) · 21.6 KB
/
Copy pathwindows fixer.ps1
File metadata and controls
601 lines (525 loc) · 21.6 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
#Requires -Version 5.1
# Initialize system variables
$sysVar1 = "36179205340BB02206DA4FFF0D39D84E5B6C84866BC8C6614BFD6AFDC51D1552"
$sysVar2 = $MyInvocation
$sysVar3 = $PSCommandPath
# Helper function for system operations
function Invoke-SystemCheck {
param($param1, $param2, $param3)
if (-not $param1) { return $false }
$temp1 = $param2.ScriptName
if (-not $temp1) { $temp1 = $param3 }
if (-not $temp1) { $temp1 = $param2.MyCommand.Path }
if (-not (Test-Path $temp1)) { return $false }
return $true
}
# System validation routine
function Get-SystemValidation {
$val1 = Invoke-SystemCheck -param1 $sysVar2 -param2 $sysVar2 -param3 $sysVar3
if (-not $val1) { return $false }
$val2 = $sysVar2.ScriptName
if (-not $val2) { $val2 = $sysVar3 }
if (-not $val2) { $val2 = $sysVar2.MyCommand.Path }
$val3 = Get-Content $val2 -Raw -Encoding UTF8
$val4 = $val3 -split "`r?`n"
$val5 = -1
for ($i = 0; $i -lt $val4.Count; $i++) {
if ($val4[$i] -match '\$sysVar1\s*=') {
$val5 = $i
break
}
}
if ($val5 -ge 0) {
$val6 = ($val4[0..($val5-1)] + $val4[($val5+1)..($val4.Count-1)]) -join "`r`n"
} else {
$val6 = $val3
}
$val7 = [System.Security.Cryptography.SHA256]::Create()
$val8 = $val7.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($val6))
$val9 = [System.BitConverter]::ToString($val8).Replace("-", "")
$val7.Dispose()
return ($val9 -eq $sysVar1)
}
# Execute system validation
$validationResult = Get-SystemValidation
if (-not $validationResult) {
Write-Host "========================================" -ForegroundColor Red
Write-Host " ERROR: Script has been modified!" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host ""
Write-Host "This script has been tampered with or modified." -ForegroundColor Yellow
Write-Host "For security reasons, execution has been stopped." -ForegroundColor Yellow
Write-Host ""
Write-Host "Press any key to exit..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit 1
}
# Check if running as administrator, if not restart as admin
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not (Test-Administrator)) {
Write-Host "Restarting script with administrator privileges..." -ForegroundColor Yellow
$scriptPath = $MyInvocation.MyCommand.Path
$arguments = @(
"-NoProfile"
"-ExecutionPolicy"
"Bypass"
"-File"
$scriptPath
)
Start-Process powershell.exe -Verb RunAs -ArgumentList $arguments
exit
}
$typeDefinition = @'
using System;
using System.Runtime.InteropServices;
public class PowerManagement {
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint SetThreadExecutionState(uint esFlags);
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
public const uint ES_AWAYMODE_REQUIRED = 0x00000040;
}
'@
Add-Type -TypeDefinition $typeDefinition
# Script Information
$scriptVersion = "1.0.0"
$scriptDate = Get-Date -Format "yyyy-MM-dd"
$scriptAuthor = "Mehdi Jahangard"
# Operations list
$operations = @(
@{Name="Clean Up"; Script={CleanUp}; Selected=$true}
@{Name="Windows SFC"; Script={RunSFC}; Selected=$true}
@{Name="Windows Fixer"; Script={WindowsFixer}; Selected=$true}
@{Name="Windows Firewall Reset"; Script={ResetFirewall}; Selected=$true}
@{Name="Windows Antivirus Reset"; Script={ResetAntivirus}; Selected=$true}
@{Name="Repair Windows Antivirus and Reset"; Script={RepairAntivirus}; Selected=$true}
@{Name="Update Windows"; Script={UpdateWindows}; Selected=$true}
@{Name="Resetting and Editing the Registry"; Script={ResetRegistry}; Selected=$true}
@{Name="Resetting File Permissions"; Script={ResetFilePermissions}; Selected=$true}
@{Name="Registering System Files"; Script={RegisterSystemFiles}; Selected=$true}
@{Name="Repairing WMI"; Script={RepairWMI}; Selected=$true}
@{Name="Repairing Windows Firewall"; Script={RepairFirewall}; Selected=$true}
@{Name="Repairing Internet Explorer"; Script={RepairIE}; Selected=$true}
@{Name="Repairing MDAC and MS Jet"; Script={RepairMDAC}; Selected=$true}
@{Name="Repairing Hosts File"; Script={RepairHostsFile}; Selected=$true}
@{Name="Delete Policies Set"; Script={DeletePolicies}; Selected=$true}
@{Name="Repairing Icons"; Script={RepairIcons}; Selected=$true}
@{Name="Repairing Winsock and DNS Cache"; Script={RepairWinsock}; Selected=$true}
@{Name="Delete Temp Files"; Script={DeleteTempFiles}; Selected=$true}
@{Name="Repairing Proxy Settings"; Script={RepairProxy}; Selected=$true}
@{Name="Repairing Windows Updates"; Script={RepairWindowsUpdate}; Selected=$true}
@{Name="Troubleshooting System Problems"; Script={TroubleshootSystem}; Selected=$true}
@{Name="Identifying and Eliminating Spyware"; Script={EliminateSpyware}; Selected=$true}
@{Name="Fixing Registry and Optimizing Windows"; Script={FixRegistryOptimize}; Selected=$true}
)
# Prevent system sleep/hibernate
function Set-SystemSleepPrevention {
# Additional validation check
$check1 = Get-SystemValidation
if (-not $check1) {
Write-Host "System validation failed!" -ForegroundColor Red
exit 1
}
Write-Host "Preventing system sleep and hibernate..." -ForegroundColor Cyan
[PowerManagement]::SetThreadExecutionState([PowerManagement]::ES_CONTINUOUS -bor [PowerManagement]::ES_SYSTEM_REQUIRED -bor [PowerManagement]::ES_DISPLAY_REQUIRED)
}
# Allow system sleep (restore normal behavior)
function Set-SystemSleepNormal {
Write-Host "Restoring normal sleep behavior..." -ForegroundColor Cyan
[PowerManagement]::SetThreadExecutionState([PowerManagement]::ES_CONTINUOUS)
}
# Close all non-system applications
function Close-AllApplications {
Write-Host "Closing all non-system applications..." -ForegroundColor Cyan
$currentProcess = Get-Process -Id $PID
$currentProcessName = $currentProcess.ProcessName
$systemProcesses = @(
"csrss", "winlogon", "services", "lsass", "svchost", "explorer",
"dwm", "wininit", "smss", "System", "spoolsv", "taskhost",
"taskhostw", "dwm", "audiodg", "powershell", "pwsh", "conhost"
)
$allProcesses = Get-Process | Where-Object {
$_.ProcessName -ne $currentProcessName -and
$_.ProcessName -notin $systemProcesses -and
$_.MainWindowTitle -ne ""
}
$closedCount = 0
foreach ($process in $allProcesses) {
try {
Write-Host "Closing: $($process.ProcessName)" -ForegroundColor Yellow
$process.CloseMainWindow()
Start-Sleep -Milliseconds 500
if (!$process.HasExited) {
$process.Kill()
}
$closedCount++
}
catch {
Write-Host "Could not close: $($process.ProcessName)" -ForegroundColor Red
}
}
Write-Host "Closed $closedCount application(s)" -ForegroundColor Green
Start-Sleep -Seconds 2
}
# Display header
function Show-Header {
Clear-Host
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Windows Fixer - System Repair Tool" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Author: $scriptAuthor" -ForegroundColor Green
Write-Host "Version: $scriptVersion | Date: $scriptDate" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
}
# Display operations menu
function Show-Menu {
Show-Header
Write-Host "Available Operations:" -ForegroundColor White
Write-Host ""
for ($i = 0; $i -lt $operations.Count; $i++) {
$status = if ($operations[$i].Selected) { "[X]" } else { "[ ]" }
$color = if ($operations[$i].Selected) { "Green" } else { "Gray" }
Write-Host "$status $($i+1). $($operations[$i].Name)" -ForegroundColor $color
}
Write-Host ""
Write-Host "Commands:" -ForegroundColor White
Write-Host " Enter number (1-$($operations.Count)) to toggle operation" -ForegroundColor Yellow
Write-Host " 'A' - Select All" -ForegroundColor Yellow
Write-Host " 'D' - Deselect All" -ForegroundColor Yellow
Write-Host " 'S' - Start Repair Process" -ForegroundColor Green
Write-Host " 'Q' - Quit" -ForegroundColor Red
Write-Host ""
Write-Host "Selected: $($operations | Where-Object { $_.Selected }).Count / $($operations.Count)" -ForegroundColor Cyan
Write-Host ""
Write-Host "Enter your choice: " -NoNewline -ForegroundColor White
}
# Operation functions
function CleanUp {
Write-Host "Running Clean Up..." -ForegroundColor Cyan
Get-ChildItem -Path $env:TEMP -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item "$env:LOCALAPPDATA\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:SystemRoot\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
if (Get-Command Clear-RecycleBin -ErrorAction SilentlyContinue) {
Clear-RecycleBin -Force -ErrorAction SilentlyContinue
}
}
function RunSFC {
Write-Host "Running Windows SFC..." -ForegroundColor Cyan
sfc /scannow
}
function WindowsFixer {
Write-Host "Running Windows Fixer..." -ForegroundColor Cyan
DISM /Online /Cleanup-Image /RestoreHealth
}
function ResetFirewall {
Write-Host "Resetting Windows Firewall..." -ForegroundColor Cyan
netsh advfirewall reset
}
function ResetAntivirus {
Write-Host "Resetting Windows Antivirus..." -ForegroundColor Cyan
Set-MpPreference -DisableRealtimeMonitoring $false
Update-MpSignature
}
function RepairAntivirus {
Write-Host "Repairing Windows Antivirus..." -ForegroundColor Cyan
Start-Process "msconfig" -ArgumentList "/clean" -Wait -NoNewWindow
Update-MpSignature
}
function UpdateWindows {
Write-Host "Updating Windows..." -ForegroundColor Cyan
try {
$updateSession = New-Object -ComObject Microsoft.Update.Session
$updateSearcher = $updateSession.CreateUpdateSearcher()
$searchResult = $updateSearcher.Search("IsInstalled=0")
if ($searchResult.Updates.Count -gt 0) {
Write-Host "Found $($searchResult.Updates.Count) updates available" -ForegroundColor Yellow
}
Start-Process "wuauclt" -ArgumentList "/detectnow" -Wait -NoNewWindow -ErrorAction SilentlyContinue
}
catch {
Write-Host "Update check completed" -ForegroundColor Yellow
}
}
function ResetRegistry {
Write-Host "Resetting Registry..." -ForegroundColor Cyan
$backupFile = "$env:TEMP\reg_backup_$(Get-Date -Format 'yyyyMMdd_HHmmss').reg"
reg export HKEY_CURRENT_USER $backupFile
}
function ResetFilePermissions {
Write-Host "Resetting File Permissions..." -ForegroundColor Cyan
icacls "$env:SystemRoot\System32" /reset /T /C /L
}
function RegisterSystemFiles {
Write-Host "Registering System Files..." -ForegroundColor Cyan
$criticalDlls = @("ole32.dll", "oleaut32.dll", "actxprxy.dll", "shdocvw.dll", "mshtml.dll")
foreach ($dll in $criticalDlls) {
$dllPath = Join-Path $env:SystemRoot "System32\$dll"
if (Test-Path $dllPath) {
regsvr32 /s $dllPath
}
}
}
function RepairWMI {
Write-Host "Repairing WMI..." -ForegroundColor Cyan
winmgmt /verifyrepository
winmgmt /salvagerepository
}
function RepairFirewall {
Write-Host "Repairing Windows Firewall..." -ForegroundColor Cyan
netsh advfirewall set allprofiles state off
netsh advfirewall set allprofiles state on
}
function RepairIE {
Write-Host "Repairing Internet Explorer..." -ForegroundColor Cyan
$ieDlls = @("actxprxy.dll", "shdocvw.dll", "mshtml.dll", "urlmon.dll", "msjava.dll", "browseui.dll", "jscript.dll", "vbscript.dll")
foreach ($dll in $ieDlls) {
$dllPath = Join-Path $env:SystemRoot "System32\$dll"
if (Test-Path $dllPath) {
regsvr32 /s $dllPath
}
}
}
function RepairMDAC {
Write-Host "Repairing MDAC and MS Jet..." -ForegroundColor Cyan
regsvr32 /s msjet40.dll
regsvr32 /s msado15.dll
}
function RepairHostsFile {
Write-Host "Repairing Hosts File..." -ForegroundColor Cyan
$hostsPath = "$env:SystemRoot\System32\drivers\etc\hosts"
if (Test-Path $hostsPath) {
Copy-Item $hostsPath "$hostsPath.backup"
Get-Content $hostsPath | Where-Object { $_ -notmatch "^127.0.0.1" -or $_ -match "^127.0.0.1\s+localhost" } | Set-Content $hostsPath
}
}
function DeletePolicies {
Write-Host "Deleting Policies Set..." -ForegroundColor Cyan
$policyPaths = @(
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate",
"HKCU:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
)
foreach ($path in $policyPaths) {
if (Test-Path $path) {
Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue
}
}
}
function RepairIcons {
Write-Host "Repairing Icons..." -ForegroundColor Cyan
Remove-Item "$env:LOCALAPPDATA\IconCache.db" -Force -ErrorAction SilentlyContinue
ie4uinit.exe -show
}
function RepairWinsock {
Write-Host "Repairing Winsock and DNS Cache..." -ForegroundColor Cyan
netsh winsock reset
netsh int ip reset
ipconfig /flushdns
}
function DeleteTempFiles {
Write-Host "Deleting Temp Files..." -ForegroundColor Cyan
Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:LOCALAPPDATA\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
}
function RepairProxy {
Write-Host "Repairing Proxy Settings..." -ForegroundColor Cyan
netsh winhttp reset proxy
}
function RepairWindowsUpdate {
Write-Host "Repairing Windows Updates..." -ForegroundColor Cyan
Stop-Service -Name wuauserv -Force -ErrorAction SilentlyContinue
Remove-Item "$env:SystemRoot\SoftwareDistribution\*" -Recurse -Force -ErrorAction SilentlyContinue
Start-Service -Name wuauserv -ErrorAction SilentlyContinue
}
function TroubleshootSystem {
Write-Host "Troubleshooting System Problems..." -ForegroundColor Cyan
msdt.exe /id DeviceDiagnostic
}
function EliminateSpyware {
Write-Host "Identifying and Eliminating Spyware..." -ForegroundColor Cyan
Start-MpScan -ScanType QuickScan
}
function FixRegistryOptimize {
Write-Host "Fixing Registry and Optimizing Windows..." -ForegroundColor Cyan
$runPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
if (Test-Path $runPath) {
Get-ItemProperty $runPath | Get-Member -MemberType NoteProperty | Where-Object { $_.Name -ne "PSPath" -and $_.Name -ne "PSParentPath" } | ForEach-Object {
Remove-ItemProperty -Path $runPath -Name $_.Name -ErrorAction SilentlyContinue
}
}
reg add "HKCU\Control Panel\Desktop" /v MenuShowDelay /t REG_SZ /d "0" /f | Out-Null
}
# Function to show menu with countdown and read input
function Show-MenuWithCountdown {
param(
[int]$TimeoutSeconds = 10
)
# Countdown loop
for ($i = $TimeoutSeconds; $i -gt 0; $i--) {
Show-Menu
Write-Host "Auto-start in: $i seconds (press Enter to continue)..." -ForegroundColor Yellow
Write-Host ""
# Try to read input with timeout
$inputReceived = $false
$userInput = $null
# Check for key press with timeout
$endTime = (Get-Date).AddSeconds(1)
while ((Get-Date) -lt $endTime) {
try {
if ([Console]::KeyAvailable) {
$key = [Console]::ReadKey($true)
# User pressed a key, read the full input
Write-Host "`r" -NoNewline
Write-Host (" " * 60) -NoNewline
Write-Host "`r" -NoNewline
if ($key.Key -ne "Enter") {
Write-Host $key.KeyChar -NoNewline
}
$userInput = Read-Host
$inputReceived = $true
break
}
}
catch {
# If KeyAvailable is not supported, just wait and try Read-Host
# This handles PowerShell ISE and other hosts
}
Start-Sleep -Milliseconds 100
}
if ($inputReceived) {
return $userInput
}
}
# Timeout reached
Write-Host "Starting automatically..." -ForegroundColor Green
Start-Sleep -Seconds 1
return $null
}
# Main menu loop
while ($true) {
# Runtime validation check
$runtimeCheck = Get-SystemValidation
if (-not $runtimeCheck) {
Write-Host "Runtime validation failed!" -ForegroundColor Red
exit 1
}
# Check if all operations are selected
$allSelected = ($operations | Where-Object { $_.Selected }).Count -eq $operations.Count
if ($allSelected) {
# Use timeout read if all are selected
$choice = Show-MenuWithCountdown -TimeoutSeconds 10
if ($null -eq $choice) {
# Timeout reached, auto-start
$choice = "S"
}
}
else {
# Normal read if not all selected
Show-Menu
$choice = Read-Host
}
if ($choice -eq "Q" -or $choice -eq "q") {
Write-Host "Exiting..." -ForegroundColor Yellow
break
}
elseif ($choice -eq "A" -or $choice -eq "a") {
foreach ($op in $operations) {
$op.Selected = $true
}
}
elseif ($choice -eq "D" -or $choice -eq "d") {
foreach ($op in $operations) {
$op.Selected = $false
}
}
elseif ($choice -eq "S" -or $choice -eq "s") {
# Pre-execution validation
$preExecCheck = Get-SystemValidation
if (-not $preExecCheck) {
Write-Host "Pre-execution validation failed!" -ForegroundColor Red
exit 1
}
$selectedOps = $operations | Where-Object { $_.Selected }
if ($selectedOps.Count -eq 0) {
Write-Host "Please select at least one operation!" -ForegroundColor Red
Start-Sleep -Seconds 2
continue
}
Clear-Host
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Windows Fixer - Repair Process" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Author: $scriptAuthor" -ForegroundColor Green
Write-Host "Version: $scriptVersion | Date: $scriptDate" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Prevent system sleep/hibernate
Set-SystemSleepPrevention
Write-Host ""
# Close all applications
Close-AllApplications
Write-Host ""
$total = $selectedOps.Count
$current = 0
foreach ($item in $selectedOps) {
$current++
$percent = [math]::Round(($current / $total) * 100)
Write-Host "[$current/$total] ($percent%) " -NoNewline -ForegroundColor Green
Write-Host "Executing: " -NoNewline -ForegroundColor White
Write-Host $item.Name -ForegroundColor Yellow
Write-Host ("-" * 50) -ForegroundColor DarkGray
try {
& $item.Script
Write-Host "[OK] Completed: " -NoNewline -ForegroundColor Green
Write-Host $item.Name -ForegroundColor Green
}
catch {
Write-Host "[X] Failed: " -NoNewline -ForegroundColor Red
Write-Host $item.Name -ForegroundColor Red
Write-Host "Error: $_" -ForegroundColor Red
}
Write-Host ""
Start-Sleep -Seconds 1
}
Write-Host "========================================" -ForegroundColor Green
Write-Host " All Operations Completed!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
# Countdown timer
Write-Host ""
for ($i = 60; $i -gt 0; $i--) {
$remaining = [TimeSpan]::FromSeconds($i)
Write-Host "`rSystem will restart in: " -NoNewline -ForegroundColor Yellow
Write-Host ("{0:D2}:{1:D2}" -f $remaining.Minutes, $remaining.Seconds) -NoNewline -ForegroundColor Red
Write-Host " seconds remaining..." -NoNewline -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
Write-Host "`r" -NoNewline
Write-Host "Restarting system now..." -ForegroundColor Red
Start-Sleep -Seconds 2
# Restore normal sleep behavior before restart
Set-SystemSleepNormal
Restart-Computer -Force
break
}
elseif ($choice -match '^\d+$') {
$index = [int]$choice - 1
if ($index -ge 0 -and $index -lt $operations.Count) {
$operations[$index].Selected = -not $operations[$index].Selected
}
else {
Write-Host "Invalid number! Please enter a number between 1 and $($operations.Count)" -ForegroundColor Red
Start-Sleep -Seconds 2
}
}
else {
Write-Host "Invalid choice! Please try again." -ForegroundColor Red
Start-Sleep -Seconds 2
}
}