-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysrefresh.ps1
More file actions
94 lines (85 loc) · 3.49 KB
/
sysrefresh.ps1
File metadata and controls
94 lines (85 loc) · 3.49 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
# ▓▓▓ SYSREFRESH TOOLKIT ▓▓▓
# Version-aware diagnostics + driver recovery
# Compatible with PowerShell Core and Windows PowerShell
# ─────────────────────────────────────────────────
# Helper: Log Writer
Checkpoint-Computer -Description "SysRefresh Toolkit" -RestorePointType "MODIFY_SETTINGS"
function Write-Log {
param([string]$Message)
$stamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path "$env:SystemDrive\SysRefresh.log" -Value "$stamp → $Message"
}
# ░ Check NuGet Provider ░
function Test-NuGetProvider {
if (Get-PackageProvider -ListAvailable | Where-Object { $_.Name -eq 'NuGet' }) {
Write-Host "[✓] NuGet provider is present."
Write-Log "NuGet provider verified."
} else {
Write-Host "[✗] NuGet provider missing."
Write-Log "NuGet provider missing."
}
}
# ░ Refresh Drivers ░
function Update-AllDrivers {
Write-Host "[↻] Reinstalling published drivers..."
pnputil /enum-drivers | ForEach-Object {
if ($_ -match "Published Name\s*:\s*(.+)") {
$publishedName = $matches[1]
pnputil /install-driver $publishedName /force
}
}
Write-Log "All drivers reinstalled from local store."
}
# ░ Run Windows Update ░
function Invoke-WindowsUpdate {
Import-Module PSWindowsUpdate -ErrorAction SilentlyContinue
Write-Host "[🔄] Windows Update execution started..."
Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -Verbose
Write-Log "Windows Update executed."
}
# ░ Performance Scan (Core-safe) ░
function Invoke-PerformanceScan {
Write-Host "[📊] Running memory and system checks..."
$sysMetrics = Get-CimInstance Win32_OperatingSystem |
Select-Object FreePhysicalMemory, TotalVisibleMemorySize, LastBootUpTime
$cpuMetrics = Get-CimInstance Win32_Processor |
Select-Object Name, LoadPercentage, NumberOfLogicalProcessors
Write-Log "Performance scan completed."
$sysMetrics
$cpuMetrics
}
# ░ WMI Repair ░
function Repair-WMI {
Write-Host "[🧼] Repairing WMI repository..."
net stop winmgmt /y
Rename-Item "$env:windir\System32\wbem\Repository" -NewName "Repository.old" -Force
net start winmgmt
$mofList = @("cimwin32.mof", "mgmt.mof", "wmiprov.mof", "rsop.mof")
foreach ($mof in $mofList) {
mofcomp "$env:windir\System32\wbem\$mof"
}
Write-Log "WMI repair routine completed."
}
# ░ Kernel Trace (ETW) ░
function Trace-KernelPerformance {
$sessionName = "PostKaliTrace"
Write-Host "[⏱️] Starting kernel trace for 60s..."
wpr -start CPU -start DiskIO -start Registry -filemode
Start-Sleep -Seconds 60
wpr -stop "$env:SystemDrive\SysRefresh-$sessionName.etl"
Write-Log "Kernel trace saved to SysRefresh-$sessionName.etl"
Write-Host "[🧠] ETL trace file saved."
}
# ░ Master Run ░
function Start-Toolkit {
Write-Host "[🚀] Starting SysRefresh session..."
Test-NuGetProvider
Update-AllDrivers
Invoke-WindowsUpdate
Invoke-PerformanceScan
Trace-KernelPerformance
Write-Host "`n[✔] SysRefresh tasks completed. Review logs at C:\SysRefresh.log"
}
# ─────────────────────────────────────────────────
# Optional: Run the full sequence
Start-Toolkit