-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthSystem.ps1
More file actions
75 lines (52 loc) · 2.09 KB
/
Copy pathHealthSystem.ps1
File metadata and controls
75 lines (52 loc) · 2.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
#requires -RunAsAdministrator
#using module D:\software\scripts\Modules\Windows\Health\SfcScanner.ps1
Set-StrictMode -Version Latest
. "$PSScriptRoot\Modules\LoadModule.ps1" -ModuleNames @("Windows.Health") -Force | Out-Null
enum DismHealthStatus {
Healthy
Repairable
Error
}
#. D:\software\scripts\Modules\Windows\Health\SfcScanner.ps1
# this file should save with encoding utf8 with bom, otherwise dism.exe output will be garbled and unreadable.
# If you see garbled text in the log file, please change the encoding of this file to utf8 with bom and run again.
function SfcCheck {
$sfc = New-SfcScannerObject
$scanResult = $sfc.ScanOnly()
if ($scanResult.IntegrityViolations) {
Write-Host "System file corruption detected!" -ForegroundColor Red
if ($scanResult.CorruptedFiles.Count -gt 0) {
Write-Host "Corrupted files: $($scanResult.CorruptedFiles.Count)" -ForegroundColor Yellow
$repairResult = $sfc.ScanAndRepair()
if ($repairResult.Success) {
Write-Host "Repair completed successfully!" -ForegroundColor Green
Write-Host "Repaired $($repairResult.RepairedFiles.Count) files"
}
else {
Write-Host "Repair failed or incomplete!" -ForegroundColor Red
if ($repairResult.CouldNotRepairFiles.Count -gt 0) {
Write-Host "Files that could not be repaired:"
$repairResult.CouldNotRepairFiles | Write-Host -ForegroundColor Red
}
}
}
}
else {
Write-Host "System integrity verified - no issues found" -ForegroundColor Green
}
}
function DismCheck {
$dism = New-DismManager
$_result = $dism.CheckHealth()
Show-DismResult -Result $_result
# Check health
if ($_result.Health -eq [DismHealthStatus]::Repairable) {
$_result = $dism.ScanHealth()
Show-DismResult -Result $_result
if ($_result.Health -eq [DismHealthStatus]::Healthy) {
Write-Host "Image health check passed"
}
}
}
SfcCheck
DismCheck