-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemTester.ps1
More file actions
1845 lines (1633 loc) · 73.7 KB
/
SystemTester.ps1
File metadata and controls
1845 lines (1633 loc) · 73.7 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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Portable Sysinternals System Tester
# Created by Pacific Northwest Computers - 2025
# Complete Production Version - v2.21
param([switch]$AutoRun)
# Constants
$script:VERSION = "2.21"
$script:DXDIAG_TIMEOUT = 45
$script:ENERGY_DURATION = 15
$script:CPU_TEST_SECONDS = 10
$script:MAX_PATH_LENGTH = 240
$script:MIN_TOOL_SIZE_KB = 50
# Paths
$ScriptRoot = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path }
$DriveLetter = (Split-Path -Qualifier $ScriptRoot).TrimEnd('\')
$SysinternalsPath = Join-Path $ScriptRoot "Sysinternals"
# Global state
$script:TestResults = @()
$script:IsAdmin = $false
$script:LaunchedViaBatch = $false
Write-Host "========================================" -ForegroundColor Green
Write-Host " SYSINTERNALS TESTER v$script:VERSION" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host "Running from: $DriveLetter" -ForegroundColor Cyan
# Detect if launched via batch file
function Test-LauncherAwareness {
try {
$parentPID = (Get-Process -Id $PID).Parent.Id
if ($parentPID) {
$parentProcess = Get-CimInstance Win32_Process -Filter "ProcessId=$parentPID" -ErrorAction Stop
if ($parentProcess.Name -eq "cmd.exe") {
$script:LaunchedViaBatch = $true
Write-Host "Launcher: Batch file detected" -ForegroundColor DarkGray
return $true
}
}
} catch {}
Write-Host "Launcher: Direct PowerShell execution" -ForegroundColor DarkGray
return $false
}
# Check admin privileges
function Test-AdminPrivileges {
try {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
$script:IsAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($script:IsAdmin) {
Write-Host "Administrator: YES" -ForegroundColor Green
} else {
Write-Host "Administrator: NO (limited functionality)" -ForegroundColor Yellow
}
return $script:IsAdmin
} catch {
return $false
}
}
# Tool integrity verification
function Test-ToolIntegrity {
param([string]$ToolName)
$toolPath = Join-Path $SysinternalsPath "$ToolName.exe"
# Check if file exists
if (!(Test-Path $toolPath)) {
return @{Status="MISSING"; Details="File not found"}
}
# Check file size
$fileInfo = Get-Item $toolPath
if ($fileInfo.Length -lt ($script:MIN_TOOL_SIZE_KB * 1KB)) {
return @{Status="BAD_SIZE"; Details="File too small: $($fileInfo.Length) bytes"}
}
# Check digital signature
try {
$signature = Get-AuthenticodeSignature $toolPath -ErrorAction Stop
if ($signature.Status -eq "Valid") {
$subject = $signature.SignerCertificate.Subject
if ($subject -match "Microsoft Corporation") {
return @{Status="VALID_MS"; Details="Valid Microsoft signature"}
} else {
return @{Status="VALID_OTHER"; Details="Valid non-Microsoft signature: $subject"}
}
} elseif ($signature.Status -eq "NotSigned") {
return @{Status="NOT_SIGNED"; Details="File is not digitally signed"}
} else {
return @{Status="BAD_SIGNATURE"; Details="Signature status: $($signature.Status)"}
}
} catch {
return @{Status="CHECK_FAILED"; Details="Error: $($_.Exception.Message)"}
}
}
# Verify all tools
function Test-ToolVerification {
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " TOOL INTEGRITY VERIFICATION" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
$allTools = @(
"psinfo","coreinfo","pslist","handle","clockres",
"autorunsc","du","streams","contig","sigcheck",
"testlimit","diskext","listdlls"
)
$stats = @{
VALID_MS=0; VALID_OTHER=0; NOT_SIGNED=0
BAD_SIZE=0; BAD_SIGNATURE=0; MISSING=0; CHECK_FAILED=0
}
foreach ($tool in $allTools) {
$result = Test-ToolIntegrity -ToolName $tool
$stats[$result.Status]++
$color = switch ($result.Status) {
"VALID_MS" { "Green" }
"VALID_OTHER" { "Cyan" }
"NOT_SIGNED" { "Yellow" }
"MISSING" { "Red" }
"BAD_SIZE" { "Red" }
"BAD_SIGNATURE" { "Red" }
"CHECK_FAILED" { "Yellow" }
}
$statusText = switch ($result.Status) {
"VALID_MS" { "[OK-MS]" }
"VALID_OTHER" { "[OK-OTHER]" }
"NOT_SIGNED" { "[NO-SIG]" }
"MISSING" { "[MISSING]" }
"BAD_SIZE" { "[BAD-SIZE]" }
"BAD_SIGNATURE" { "[BAD-SIG]" }
"CHECK_FAILED" { "[ERROR]" }
}
Write-Host "$statusText $tool" -ForegroundColor $color
if ($result.Details -and $result.Status -ne "VALID_MS") {
Write-Host " $($result.Details)" -ForegroundColor DarkGray
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "SUMMARY:" -ForegroundColor White
Write-Host " Valid (Microsoft): $($stats.VALID_MS)" -ForegroundColor Green
Write-Host " Valid (Other): $($stats.VALID_OTHER)" -ForegroundColor Cyan
Write-Host " Not Signed: $($stats.NOT_SIGNED)" -ForegroundColor Yellow
Write-Host " Bad Size: $($stats.BAD_SIZE)" -ForegroundColor Red
Write-Host " Bad Signature: $($stats.BAD_SIGNATURE)" -ForegroundColor Red
Write-Host " Missing: $($stats.MISSING)" -ForegroundColor Red
Write-Host " Check Failed: $($stats.CHECK_FAILED)" -ForegroundColor Yellow
Write-Host ""
$totalIssues = $stats.BAD_SIZE + $stats.BAD_SIGNATURE + $stats.MISSING + $stats.CHECK_FAILED
if ($totalIssues -eq 0 -and $stats.VALID_MS -gt 0) {
Write-Host "STATUS: All present tools are verified and safe to use" -ForegroundColor Green
} elseif ($totalIssues -gt 0) {
Write-Host "STATUS: $totalIssues issue(s) detected - recommend re-download" -ForegroundColor Yellow
if ($script:LaunchedViaBatch) {
Write-Host "ACTION: Use Batch Menu Option 5 to re-download tools" -ForegroundColor Yellow
}
}
Write-Host ""
}
# Initialize environment
function Initialize-Environment {
Write-Host "Initializing..." -ForegroundColor Yellow
Test-LauncherAwareness | Out-Null
Test-AdminPrivileges | Out-Null
# Path length check
if ($ScriptRoot.Length -gt $script:MAX_PATH_LENGTH) {
Write-Host "WARNING: Path length is $($ScriptRoot.Length) chars" -ForegroundColor Yellow
Write-Host " Consider moving to shorter path (Windows limit: 260)" -ForegroundColor Yellow
}
# Check tools folder
if (!(Test-Path $SysinternalsPath)) {
Write-Host "ERROR: Sysinternals folder not found!" -ForegroundColor Red
Write-Host "Expected: $SysinternalsPath" -ForegroundColor Yellow
if ($script:LaunchedViaBatch) {
Write-Host "ACTION: Use Batch Menu Option 5 to download tools automatically" -ForegroundColor Yellow
} else {
Write-Host "ACTION: Download from https://download.sysinternals.com/files/SysinternalsSuite.zip" -ForegroundColor Yellow
Write-Host " Extract to: $SysinternalsPath" -ForegroundColor Yellow
}
return $false
}
# Check for key tools
$tools = @("psinfo.exe","coreinfo.exe","pslist.exe","handle.exe","clockres.exe")
$found = 0
$missing = @()
foreach ($tool in $tools) {
if (Test-Path (Join-Path $SysinternalsPath $tool)) {
$found++
} else {
$missing += $tool
}
}
if ($found -eq 0) {
Write-Host "ERROR: No tools found in $SysinternalsPath" -ForegroundColor Red
if ($script:LaunchedViaBatch) {
Write-Host "ACTION: Use Batch Menu Option 5 to download tools" -ForegroundColor Yellow
}
return $false
}
Write-Host "Found $found/$($tools.Count) key tools" -ForegroundColor Green
if ($missing.Count -gt 0) {
Write-Host "Missing: $($missing -join ', ')" -ForegroundColor Yellow
if ($script:LaunchedViaBatch) {
Write-Host "TIP: Use Batch Menu Option 4 for integrity check" -ForegroundColor DarkYellow
Write-Host " Use Batch Menu Option 5 to update tools" -ForegroundColor DarkYellow
}
}
return $true
}
# Clean tool output
function Convert-ToolOutput {
param([string]$ToolName, [string]$RawOutput)
if (!$RawOutput) { return "" }
$lines = $RawOutput -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ }
$cleaned = @()
foreach ($line in $lines) {
# Skip boilerplate
if ($line -match "Copyright|Sysinternals|www\.|EULA|Mark Russinovich|David Solomon|Bryce Cogswell") { continue }
if ($line -match "^-+$|^=+$|^\*+$") { continue }
# Tool-specific filtering
switch ($ToolName) {
"psinfo" {
if ($line -match "^(System|Uptime|Kernel|Product|Service|Build|Processors|Physical|Computer|Domain|Install)") {
$cleaned += $line
}
}
"coreinfo" {
if ($line -match "^(Intel|AMD|Logical|Cores|Processor|CPU|Cache|Feature|\s+\*)") {
$cleaned += $line
}
}
"pslist" {
if ($line -match "^(Name|Process|Pid)\s+|^\w+\s+\d+") {
$cleaned += $line
}
}
default {
if ($line.Length -lt 200) { $cleaned += $line }
}
}
}
return ($cleaned | Select-Object -First 40) -join "`n"
}
# Run tool
function Invoke-Tool {
param(
[string]$ToolName,
[Alias('Args')]
[string]$ArgumentList = "",
[string]$Description = "",
[bool]$RequiresAdmin = $false
)
if ($RequiresAdmin -and -not $script:IsAdmin) {
Write-Host "SKIP: $ToolName (requires admin)" -ForegroundColor Yellow
$script:TestResults += @{
Tool=$ToolName; Description=$Description
Status="SKIPPED"; Output="Requires administrator privileges"; Duration=0
}
return
}
$toolPath = Join-Path $SysinternalsPath "$ToolName.exe"
if (!(Test-Path $toolPath)) {
Write-Host "SKIP: $ToolName (not found)" -ForegroundColor Yellow
return
}
Write-Host "Running $ToolName..." -ForegroundColor Cyan
try {
$start = Get-Date
if ($ToolName -in @("psinfo","pslist","handle","autorunsc","testlimit","contig")) {
$ArgumentList = "-accepteula $ArgumentList"
}
$argArray = if ($ArgumentList.Trim()) { $ArgumentList.Split(' ') | Where-Object { $_ } } else { @() }
$rawOutput = & $toolPath $argArray 2>&1 | Out-String
$duration = ((Get-Date) - $start).TotalMilliseconds
$cleanOutput = Convert-ToolOutput -ToolName $ToolName -RawOutput $rawOutput
$script:TestResults += @{
Tool=$ToolName; Description=$Description
Status="SUCCESS"; Output=$cleanOutput; Duration=$duration
}
Write-Host "OK: $ToolName ($([math]::Round($duration))ms)" -ForegroundColor Green
}
catch {
$script:TestResults += @{
Tool=$ToolName; Description=$Description
Status="FAILED"; Output="Error: $($_.Exception.Message)"; Duration=0
}
Write-Host "ERROR: $ToolName - $($_.Exception.Message)" -ForegroundColor Red
}
}
# Test: System Info
function Test-SystemInfo {
Write-Host "`n=== System Information ===" -ForegroundColor Green
Invoke-Tool -ToolName "psinfo" -ArgumentList "-h -s -d" -Description "System information"
Invoke-Tool -ToolName "clockres" -Description "Clock resolution"
try {
$os = Get-CimInstance Win32_OperatingSystem -ErrorAction Stop
$cs = Get-CimInstance Win32_ComputerSystem -ErrorAction Stop
$info = @"
OS: $($os.Caption) $($os.Version)
Architecture: $($os.OSArchitecture)
Computer: $($cs.Name)
Manufacturer: $($cs.Manufacturer)
Model: $($cs.Model)
RAM: $([math]::Round($cs.TotalPhysicalMemory/1GB,2)) GB
"@
$script:TestResults += @{
Tool="System-Overview"; Description="System overview"
Status="SUCCESS"; Output=$info; Duration=100
}
Write-Host "System overview collected" -ForegroundColor Green
} catch {
Write-Host "Error getting system info" -ForegroundColor Red
}
}
# Test: CPU
function Test-CPU {
Write-Host "`n=== CPU Testing ===" -ForegroundColor Green
Invoke-Tool -ToolName "coreinfo" -ArgumentList "-v -f -c" -Description "CPU architecture"
try {
$cpu = Get-CimInstance Win32_Processor -ErrorAction Stop | Select-Object -First 1
$info = @"
CPU: $($cpu.Name)
Cores: $($cpu.NumberOfCores)
Logical: $($cpu.NumberOfLogicalProcessors)
Speed: $($cpu.MaxClockSpeed) MHz
L2 Cache: $($cpu.L2CacheSize) KB
L3 Cache: $($cpu.L3CacheSize) KB
"@
$script:TestResults += @{
Tool="CPU-Details"; Description="CPU details"
Status="SUCCESS"; Output=$info; Duration=100
}
Write-Host "CPU details collected" -ForegroundColor Green
} catch {
Write-Host "Error getting CPU details" -ForegroundColor Yellow
}
Write-Host "Running CPU test ($script:CPU_TEST_SECONDS sec - synthetic)..." -ForegroundColor Yellow
try {
$start = Get-Date
$end = $start.AddSeconds($script:CPU_TEST_SECONDS)
$counter = 0
while ((Get-Date) -lt $end) {
$counter++
[math]::Sqrt($counter) | Out-Null
}
$duration = ((Get-Date) - $start).TotalSeconds
$opsPerSec = [math]::Round($counter / $duration)
$script:TestResults += @{
Tool="CPU-Performance"; Description="CPU performance test (synthetic)"
Status="SUCCESS"; Output="Operations: $counter`nOps/sec: $opsPerSec`nNote: Synthetic test only"; Duration=($duration*1000)
}
Write-Host "CPU test: $opsPerSec ops/sec" -ForegroundColor Green
} catch {
Write-Host "CPU test failed" -ForegroundColor Red
}
}
# Test: Memory (FIXED)
function Test-Memory {
Write-Host "`n=== RAM Testing ===" -ForegroundColor Green
try {
$mem = Get-CimInstance Win32_ComputerSystem -ErrorAction Stop
$os = Get-CimInstance Win32_OperatingSystem -ErrorAction Stop
$totalGB = [math]::Round($mem.TotalPhysicalMemory/1GB,2)
# FIX: FreePhysicalMemory is in KB, convert to GB correctly
$availGB = [math]::Round($os.FreePhysicalMemory/1024/1024,2)
$usedGB = $totalGB - $availGB
$usage = [math]::Round(($usedGB/$totalGB)*100,1)
$info = @"
Total RAM: $totalGB GB
Available: $availGB GB
Used: $usedGB GB
Usage: $usage%
"@
$script:TestResults += @{
Tool="RAM-Details"; Description="RAM information"
Status="SUCCESS"; Output=$info; Duration=100
}
Write-Host "RAM: $totalGB GB total, $usage% used" -ForegroundColor Green
} catch {
Write-Host "Error getting memory info" -ForegroundColor Red
}
}
# Test: Storage
function Test-Storage {
Write-Host "`n=== Storage Testing ===" -ForegroundColor Green
try {
$disks = Get-CimInstance Win32_LogicalDisk -ErrorAction Stop | Where-Object { $_.DriveType -eq 3 }
$info = "LOGICAL DRIVES:`n"
foreach ($disk in $disks) {
$totalGB = [math]::Round($disk.Size/1GB,2)
$freeGB = [math]::Round($disk.FreeSpace/1GB,2)
$freePercent = if ($totalGB -gt 0) { [math]::Round(($freeGB/$totalGB)*100,1) } else { 0 }
$info += "$($disk.DeviceID) - $totalGB GB total, $freeGB GB free ($freePercent%)`n"
}
$script:TestResults += @{
Tool="Storage-Overview"; Description="Storage information"
Status="SUCCESS"; Output=$info; Duration=100
}
Write-Host "Storage overview collected" -ForegroundColor Green
} catch {
Write-Host "Error getting storage info" -ForegroundColor Red
}
Invoke-Tool -ToolName "du" -ArgumentList "-l 2 C:\" -Description "Disk usage C:"
# Disk performance test
Write-Host "Running disk test..." -ForegroundColor Yellow
try {
$testFile = Join-Path $env:TEMP "disktest_$([guid]::NewGuid().ToString('N')).tmp"
$testData = "0" * 1024 * 1024
$writeStart = Get-Date
for ($i=0; $i -lt 10; $i++) {
$testData | Out-File -FilePath $testFile -Append -Encoding ASCII -ErrorAction Stop
}
$writeTime = ((Get-Date) - $writeStart).TotalMilliseconds
$readStart = Get-Date
$null = Get-Content $testFile -Raw -ErrorAction Stop
$readTime = ((Get-Date) - $readStart).TotalMilliseconds
Remove-Item $testFile -ErrorAction Stop
$writeMBps = if ($writeTime -gt 0) { [math]::Round(10/($writeTime/1000),2) } else { 0 }
$readMBps = if ($readTime -gt 0) { [math]::Round(10/($readTime/1000),2) } else { 0 }
$script:TestResults += @{
Tool="Disk-Performance"; Description="Disk performance (10MB)"
Status="SUCCESS"; Output="Write: $writeMBps MB/s`nRead: $readMBps MB/s"; Duration=($writeTime+$readTime)
}
Write-Host "Disk: Write $writeMBps MB/s, Read $readMBps MB/s" -ForegroundColor Green
} catch {
Write-Host "Disk test failed" -ForegroundColor Yellow
}
}
# Test: Processes
function Test-Processes {
Write-Host "`n=== Process Analysis ===" -ForegroundColor Green
Invoke-Tool -ToolName "pslist" -ArgumentList "-t" -Description "Process tree"
Invoke-Tool -ToolName "handle" -ArgumentList "-p explorer" -Description "Explorer handles"
}
# Test: Security
function Test-Security {
Write-Host "`n=== Security Analysis ===" -ForegroundColor Green
Invoke-Tool -ToolName "autorunsc" -ArgumentList "-a -c" -Description "Autorun entries" -RequiresAdmin $true
}
# Test: Network
function Test-Network {
Write-Host "`n=== Network Analysis ===" -ForegroundColor Green
try {
$connections = (netstat -an 2>&1 | Measure-Object).Count
$script:TestResults += @{
Tool="Netstat"; Description="Network connections"
Status="SUCCESS"; Output="Total connections: $connections"; Duration=50
}
Write-Host "Network: $connections connections" -ForegroundColor Green
} catch {
Write-Host "Error getting network info" -ForegroundColor Red
}
Test-NetworkSpeed
Test-NetworkLatency
}
function Test-NetworkSpeed {
Write-Host "`n=== Network Speed Test ===" -ForegroundColor Green
$outputLines = @()
$status = "SUCCESS"
$durationMs = 0
# Gather link speed information for active adapters
try {
$adapters = Get-NetAdapter -ErrorAction Stop | Where-Object { $_.Status -eq "Up" }
if ($adapters) {
$outputLines += "Active Link Speeds:"
foreach ($adapter in $adapters) {
$outputLines += " $($adapter.Name): $($adapter.LinkSpeed)"
}
} else {
$outputLines += "Active Link Speeds: No active adapters detected"
}
} catch {
$status = "FAILED"
$outputLines += "Active Link Speeds: Unable to query adapters ($($_.Exception.Message))"
}
# Perform an outbound download test to estimate internet throughput
$tempFile = $null
try {
$testUrl = "https://speed.hetzner.de/10MB.bin"
$tempFile = [System.IO.Path]::GetTempFileName()
Write-Host "Running internet download test (~10MB)..." -ForegroundColor Yellow
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
# Use compatible parameters across PowerShell versions
$iwc = Get-Command Invoke-WebRequest -ErrorAction SilentlyContinue
$iwParams = @{ Uri = $testUrl; OutFile = $tempFile }
if ($iwc -and $iwc.Parameters.ContainsKey('UseBasicParsing')) { $iwParams.UseBasicParsing = $true }
if ($iwc -and $iwc.Parameters.ContainsKey('TimeoutSec')) { $iwParams.TimeoutSec = 120 }
Invoke-WebRequest @iwParams | Out-Null
$stopwatch.Stop()
$fileInfo = Get-Item $tempFile
$sizeBytes = [double]$fileInfo.Length
$duration = [math]::Max($stopwatch.Elapsed.TotalSeconds, 0.001)
$sizeMB = [math]::Round($sizeBytes / 1MB, 2)
$mbps = [math]::Round((($sizeBytes * 8) / 1MB) / $duration, 2)
$mbPerSec = [math]::Round(($sizeBytes / 1MB) / $duration, 2)
$outputLines += "Internet Download Test:"
$outputLines += " URL: $testUrl"
$outputLines += " File Size: $sizeMB MB"
$outputLines += " Time: $([math]::Round($duration,2)) sec"
$outputLines += " Throughput: $mbps Mbps ($mbPerSec MB/s)"
$durationMs = [math]::Round($stopwatch.Elapsed.TotalMilliseconds)
} catch {
if ($status -ne "FAILED") { $status = "FAILED" }
$outputLines += "Internet Download Test: Failed - $($_.Exception.Message)"
} finally {
if ($tempFile -and (Test-Path $tempFile)) {
Remove-Item $tempFile -ErrorAction SilentlyContinue
}
}
$script:TestResults += @{
Tool="Network-SpeedTest"; Description="Local link speed and download throughput"
Status=$status; Output=($outputLines -join "`n"); Duration=$durationMs
}
}
function Test-NetworkLatency {
Write-Host "`n=== Network Latency (Test-NetConnection & PsPing) ===" -ForegroundColor Green
$targetHost = "8.8.8.8"
$lines = @("Target: $targetHost")
$status = "SUCCESS"
# Built-in Test-NetConnection results (ICMP only)
try {
$tnc = Test-NetConnection -ComputerName $targetHost -InformationLevel Detailed
if ($tnc) {
$lines += "Test-NetConnection:"
$lines += " Ping Succeeded: $($tnc.PingSucceeded)"
if ($tnc.PingReplyDetails) {
$lines += " Ping RTT: $($tnc.PingReplyDetails.RoundtripTime) ms"
}
}
} catch {
$status = "FAILED"
$lines += "Test-NetConnection: Failed - $($_.Exception.Message)"
}
# Sysinternals PsPing results (ICMP only)
try {
$pspingPath = Join-Path $SysinternalsPath "psping.exe"
if (Test-Path $pspingPath) {
$pspingArgs = @("-accepteula", "-n", "5", $targetHost)
Write-Host "Running PsPing latency test..." -ForegroundColor Yellow
$pspingOutput = & $pspingPath $pspingArgs 2>&1 | Out-String
$lines += "PsPing Summary:"
$average = $null
$minimum = $null
$maximum = $null
foreach ($line in $pspingOutput -split "`r?`n") {
if ($line -match "Minimum = ([\d\.]+)ms, Maximum = ([\d\.]+)ms, Average = ([\d\.]+)ms") {
$minimum = [double]$matches[1]
$maximum = [double]$matches[2]
$average = [double]$matches[3]
}
}
if ($null -ne $average) {
$lines += " Min: $minimum ms"
$lines += " Max: $maximum ms"
$lines += " Avg: $average ms"
} else {
$lines += " Unable to parse latency results"
}
} else {
$lines += "PsPing Summary: psping.exe not found in Sysinternals folder"
}
} catch {
$status = "FAILED"
$lines += "PsPing Summary: Failed - $($_.Exception.Message)"
}
$script:TestResults += @{
Tool="Network-Latency"; Description="Connectivity latency tests"
Status=$status; Output=($lines -join "`n"); Duration=0
}
}
# Test: OS Health
function Test-OSHealth {
Write-Host "`n=== OS Health (DISM/SFC) ===" -ForegroundColor Green
if (-not $script:IsAdmin) {
Write-Host "SKIP: Requires admin" -ForegroundColor Yellow
$script:TestResults += @{
Tool="OS-Health"; Description="DISM+SFC checks"
Status="SKIPPED"; Output="Requires administrator privileges"; Duration=0
}
return
}
Write-Host "Running DISM and SFC (may take 5-15 min)..." -ForegroundColor Yellow
try {
$start = Get-Date
$dism = (dism /Online /Cleanup-Image /ScanHealth) 2>&1 | Out-String
$sfc = (sfc /scannow) 2>&1 | Out-String
$duration = ((Get-Date) - $start).TotalMilliseconds
$summary = "DISM:`n" + (($dism -split "`n" | Where-Object {$_ -match "No component|repairable|error"} | Select-Object -First 3) -join "`n")
$summary += "`n`nSFC:`n" + (($sfc -split "`n" | Where-Object {$_ -match "did not find|found corrupt|Protection"} | Select-Object -First 3) -join "`n")
$script:TestResults += @{
Tool="OS-Health"; Description="DISM+SFC integrity"
Status="SUCCESS"; Output=$summary; Duration=$duration
}
Write-Host "OS Health complete" -ForegroundColor Green
} catch {
Write-Host "OS Health check failed" -ForegroundColor Red
}
}
# Test: SMART
function Test-StorageSMART {
Write-Host "`n=== Storage SMART ===" -ForegroundColor Green
try {
$lines = @()
try {
$pd = Get-PhysicalDisk -ErrorAction Stop
foreach ($p in $pd) {
$lines += "$($p.FriendlyName) | Health: $($p.HealthStatus) | Media: $($p.MediaType)"
}
} catch {}
if (-not $lines) { $lines = @("SMART data not available (driver limitation)") }
$script:TestResults += @{
Tool="Storage-SMART"; Description="SMART data"
Status="SUCCESS"; Output=($lines -join "`n"); Duration=100
}
Write-Host "SMART data collected" -ForegroundColor Green
} catch {
Write-Host "SMART check failed" -ForegroundColor Yellow
}
}
# Test: TRIM
function Test-Trim {
Write-Host "`n=== SSD TRIM Status ===" -ForegroundColor Green
try {
$q = (fsutil behavior query DisableDeleteNotify) 2>&1
$map = @{}
($q -split "`n") | ForEach-Object {
if ($_ -match "NTFS DisableDeleteNotify\s*=\s*(\d)") { $map["NTFS"] = $matches[1] }
}
$txt = $map.GetEnumerator() | ForEach-Object {
$status = if ($_.Value -eq "0") { "Enabled" } else { "Disabled" }
"$($_.Key): TRIM $status"
}
if (-not $txt) { $txt = @("TRIM status unknown") }
if ($map.Count -gt 0) {
$enabledCount = ($map.GetEnumerator() | Where-Object { $_.Value -eq "0" }).Count
if ($enabledCount -eq $map.Count) {
$txt += "Overall: TRIM is ENABLED"
} elseif ($enabledCount -eq 0) {
$txt += "Overall: TRIM is DISABLED"
} else {
$txt += "Overall: TRIM mixed (check per-filesystem status)"
}
}
$script:TestResults += @{
Tool="SSD-TRIM"; Description="TRIM status"
Status="SUCCESS"; Output=($txt -join "`n"); Duration=50
}
Write-Host "TRIM status collected" -ForegroundColor Green
} catch {
Write-Host "TRIM check failed" -ForegroundColor Yellow
}
}
# Test: NIC
function Test-NIC {
Write-Host "`n=== Network Adapters ===" -ForegroundColor Green
try {
$adapters = Get-NetAdapter -ErrorAction Stop | Where-Object {$_.Status -eq "Up"}
$lines = foreach ($a in $adapters) {
"$($a.InterfaceAlias): $($a.LinkSpeed) | MAC: $($a.MacAddress)"
}
if (-not $lines) { $lines = @("No active adapters") }
$script:TestResults += @{
Tool="NIC-Info"; Description="Network adapters"
Status="SUCCESS"; Output=($lines -join "`n"); Duration=100
}
Write-Host "Network adapters collected" -ForegroundColor Green
} catch {
Write-Host "Network adapter check failed" -ForegroundColor Yellow
}
}
# Test: GPU (Enhanced)
function Test-GPU {
Write-Host "`n=== GPU Testing (Enhanced) ===" -ForegroundColor Green
# Part 1: Detailed WMI/CIM GPU Information
Write-Host "Gathering GPU details..." -ForegroundColor Yellow
try {
$gpus = Get-CimInstance Win32_VideoController -ErrorAction Stop
$gpuCount = ($gpus | Measure-Object).Count
$gpuInfo = @()
$gpuInfo += "DETECTED GPUs: $gpuCount`n"
$index = 1
foreach ($gpu in $gpus) {
$gpuInfo += "=" * 60
$gpuInfo += "GPU #$index"
$gpuInfo += "-" * 60
$gpuInfo += "Name: $($gpu.Name)"
$gpuInfo += "Status: $($gpu.Status)"
$gpuInfo += "Adapter RAM: $([math]::Round($gpu.AdapterRAM/1GB,2)) GB"
$gpuInfo += "Driver Version: $($gpu.DriverVersion)"
$gpuInfo += "Driver Date: $($gpu.DriverDate)"
$gpuInfo += "Video Processor: $($gpu.VideoProcessor)"
$gpuInfo += "Video Architecture: $($gpu.VideoArchitecture)"
$gpuInfo += "Video Mode: $($gpu.VideoModeDescription)"
$gpuInfo += "Current Resolution: $($gpu.CurrentHorizontalResolution) x $($gpu.CurrentVerticalResolution)"
$gpuInfo += "Refresh Rate: $($gpu.CurrentRefreshRate) Hz"
$gpuInfo += "Bits Per Pixel: $($gpu.CurrentBitsPerPixel)"
$gpuInfo += "PNP Device ID: $($gpu.PNPDeviceID)"
if ($gpu.AdapterCompatibility) {
$gpuInfo += "Manufacturer: $($gpu.AdapterCompatibility)"
}
$gpuInfo += ""
$index++
}
$script:TestResults += @{
Tool="GPU-Details"; Description="Detailed GPU information"
Status="SUCCESS"; Output=($gpuInfo -join "`n"); Duration=200
}
Write-Host "GPU details collected ($gpuCount GPU(s))" -ForegroundColor Green
} catch {
Write-Host "Error getting GPU details: $($_.Exception.Message)" -ForegroundColor Yellow
}
# Part 2: Display Configuration
Write-Host "Analyzing display configuration..." -ForegroundColor Yellow
try {
$monitors = Get-CimInstance WmiMonitorID -Namespace root\wmi -ErrorAction Stop
$monitorCount = ($monitors | Measure-Object).Count
$displayInfo = @()
$displayInfo += "DETECTED DISPLAYS: $monitorCount`n"
$index = 1
foreach ($monitor in $monitors) {
$displayInfo += "Display #$index"
$displayInfo += "-" * 40
# Decode manufacturer name
if ($monitor.ManufacturerName) {
$mfg = [System.Text.Encoding]::ASCII.GetString($monitor.ManufacturerName -ne 0)
$displayInfo += "Manufacturer: $mfg"
}
# Decode product name
if ($monitor.UserFriendlyName) {
$name = [System.Text.Encoding]::ASCII.GetString($monitor.UserFriendlyName -ne 0)
$displayInfo += "Model: $name"
}
# Decode serial number
if ($monitor.SerialNumberID) {
$serial = [System.Text.Encoding]::ASCII.GetString($monitor.SerialNumberID -ne 0)
$displayInfo += "Serial: $serial"
}
$displayInfo += "Year: $($monitor.YearOfManufacture)"
$displayInfo += ""
$index++
}
$script:TestResults += @{
Tool="Display-Configuration"; Description="Display details"
Status="SUCCESS"; Output=($displayInfo -join "`n"); Duration=150
}
Write-Host "Display configuration collected ($monitorCount display(s))" -ForegroundColor Green
} catch {
Write-Host "Display configuration unavailable" -ForegroundColor Yellow
}
# Part 3: GPU Driver Details (Enhanced)
Write-Host "Checking GPU drivers..." -ForegroundColor Yellow
try {
$drivers = Get-CimInstance Win32_PnPSignedDriver -ErrorAction Stop |
Where-Object { $_.DeviceClass -eq "DISPLAY" }
$driverInfo = @()
foreach ($driver in $drivers) {
$driverInfo += "Device: $($driver.DeviceName)"
$driverInfo += "Driver: $($driver.DriverVersion)"
$driverInfo += "Provider: $($driver.DriverProviderName)"
$driverInfo += "Date: $($driver.DriverDate)"
$driverInfo += "Signer: $($driver.Signer)"
$driverInfo += "INF: $($driver.InfName)"
$driverInfo += ""
}
$script:TestResults += @{
Tool="GPU-Drivers"; Description="GPU driver information"
Status="SUCCESS"; Output=($driverInfo -join "`n"); Duration=100
}
Write-Host "GPU driver details collected" -ForegroundColor Green
} catch {
Write-Host "Driver details unavailable" -ForegroundColor Yellow
}
# Part 4: DirectX Diagnostics (Enhanced)
Write-Host "Running DirectX diagnostics..." -ForegroundColor Yellow
$dxProcess = $null
try {
$dx = Join-Path $env:TEMP "dxdiag_$([guid]::NewGuid().ToString('N')).txt"
$dxProcess = Start-Process -FilePath "dxdiag" -ArgumentList "/t",$dx -WindowStyle Hidden -PassThru
$elapsed = 0
while (!(Test-Path $dx) -and $elapsed -lt $script:DXDIAG_TIMEOUT) {
if ($dxProcess.HasExited) { break }
Start-Sleep -Milliseconds 500
$elapsed += 0.5
}
if (Test-Path $dx) {
Start-Sleep -Seconds 1
$raw = Get-Content $dx -Raw -ErrorAction Stop
Remove-Item $dx -ErrorAction SilentlyContinue
# Extract more detailed info
$dxInfo = @()
# DirectX version
if ($raw -match "DirectX Version: (.+)") {
$dxInfo += "DirectX Version: $($matches[1])"
}
# Display devices section
$lines = $raw -split "`r?`n"
$inDisplaySection = $false
$displayLines = @()
foreach ($line in $lines) {
if ($line -match "Display Devices|Display \d+") {
$inDisplaySection = $true
}
if ($inDisplaySection) {
if ($line -match "Card name:|Manufacturer:|Chip type:|DAC type:|Device Type:|Display Memory:|Dedicated Memory:|Shared Memory:|Current Mode:|Monitor Name:|Monitor Model:|Driver Name:|Driver File Version:|Driver Version:|Driver Date/Size:") {
$displayLines += $line.Trim()
}
if ($line -match "^-{20,}") {
$inDisplaySection = $false
}
}
}
$dxInfo += $displayLines
$script:TestResults += @{
Tool="GPU-DirectX"; Description="DirectX diagnostics"
Status="SUCCESS"; Output=($dxInfo -join "`n"); Duration=($elapsed*1000)
}
Write-Host "DirectX diagnostics complete" -ForegroundColor Green
} else {
throw "DxDiag timeout or failed"
}
} catch {
Write-Host "DxDiag failed: $($_.Exception.Message)" -ForegroundColor Yellow
$script:TestResults += @{
Tool="GPU-DirectX"; Description="DirectX diagnostics"
Status="FAILED"; Output="DxDiag unavailable: $($_.Exception.Message)"; Duration=0
}
} finally {
if ($dxProcess -and !$dxProcess.HasExited) {
try { $dxProcess.Kill(); $dxProcess.WaitForExit(5000) } catch {}
}
}
# Part 5: OpenGL Information
Write-Host "Checking OpenGL support..." -ForegroundColor Yellow
try {
$openglInfo = @()
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers"
if (Test-Path $regPath) {
$oglKeys = Get-ItemProperty $regPath -ErrorAction SilentlyContinue
if ($oglKeys) {
$openglInfo += "OpenGL Registry Keys Found:"
$oglKeys.PSObject.Properties | Where-Object { $_.Name -notmatch "^PS" } | ForEach-Object {
$openglInfo += "$($_.Name): $($_.Value)"
}
}
} else {
$openglInfo += "OpenGL: Registry information not available"
}
$script:TestResults += @{
Tool="GPU-OpenGL"; Description="OpenGL information"
Status="SUCCESS"; Output=($openglInfo -join "`n"); Duration=50
}
Write-Host "OpenGL check complete" -ForegroundColor Green
} catch {
Write-Host "OpenGL check skipped" -ForegroundColor DarkGray
}
# Part 6: GPU Performance Capabilities
Write-Host "Checking GPU capabilities..." -ForegroundColor Yellow
try {
$capabilities = @()
# Check for hardware acceleration
$dwm = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\Dwm" -ErrorAction SilentlyContinue
if ($dwm) {
$capabilities += "DWM Composition: Enabled"
}
# Check for GPU scheduling
$gpuScheduling = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers" -ErrorAction SilentlyContinue
if ($gpuScheduling.HwSchMode) {
$schedStatus = if ($gpuScheduling.HwSchMode -eq 2) { "Enabled" } else { "Disabled" }
$capabilities += "Hardware-Accelerated GPU Scheduling: $schedStatus"
}
# Check DirectX feature levels
$gpus = Get-CimInstance Win32_VideoController
foreach ($gpu in $gpus) {
if ($gpu.Name) {
$driverYear = $null
if ($gpu.DriverDate) {
try {
$driverYear = ([DateTime]$gpu.DriverDate).Year
} catch {
$driverYear = $null
}
}
if (-not $driverYear) {
# Fall back to a conservative default if parsing fails
$driverYear = 2014
}
$featureLevel = if ($driverYear -ge 2020) { "12_x" }