Skip to content

Commit 854a7f4

Browse files
committed
refactor: use approved verbs and fix analyzer issues
- Clean-ToolOutput -> Convert-ToolOutput (+call site) - Run-Tool -> Invoke-Tool (+call sites) - Generate-Report -> New-Report (+call sites) - Replace param with (alias Args) - Avoid automatic var in PsPing - Fix comparison order - Remove unused var - Repair GPU submenu strings causing parse error
1 parent 2c4c029 commit 854a7f4

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

SystemTester.ps1

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function Initialize-Environment {
245245
}
246246

247247
# Clean tool output
248-
function Clean-ToolOutput {
248+
function Convert-ToolOutput {
249249
param([string]$ToolName, [string]$RawOutput)
250250
if (!$RawOutput) { return "" }
251251

@@ -284,10 +284,11 @@ function Clean-ToolOutput {
284284
}
285285

286286
# Run tool
287-
function Run-Tool {
287+
function Invoke-Tool {
288288
param(
289289
[string]$ToolName,
290-
[string]$Args = "",
290+
[Alias('Args')]
291+
[string]$ArgumentList = "",
291292
[string]$Description = "",
292293
[bool]$RequiresAdmin = $false
293294
)
@@ -311,13 +312,13 @@ function Run-Tool {
311312
try {
312313
$start = Get-Date
313314
if ($ToolName -in @("psinfo","pslist","handle","autorunsc","testlimit","contig")) {
314-
$Args = "-accepteula $Args"
315+
$ArgumentList = "-accepteula $ArgumentList"
315316
}
316317

317-
$argArray = if ($Args.Trim()) { $Args.Split(' ') | Where-Object { $_ } } else { @() }
318+
$argArray = if ($ArgumentList.Trim()) { $ArgumentList.Split(' ') | Where-Object { $_ } } else { @() }
318319
$rawOutput = & $toolPath $argArray 2>&1 | Out-String
319320
$duration = ((Get-Date) - $start).TotalMilliseconds
320-
$cleanOutput = Clean-ToolOutput -ToolName $ToolName -RawOutput $rawOutput
321+
$cleanOutput = Convert-ToolOutput -ToolName $ToolName -RawOutput $rawOutput
321322

322323
$script:TestResults += @{
323324
Tool=$ToolName; Description=$Description
@@ -337,8 +338,8 @@ function Run-Tool {
337338
# Test: System Info
338339
function Test-SystemInfo {
339340
Write-Host "`n=== System Information ===" -ForegroundColor Green
340-
Run-Tool -ToolName "psinfo" -Args "-h -s -d" -Description "System information"
341-
Run-Tool -ToolName "clockres" -Description "Clock resolution"
341+
Invoke-Tool -ToolName "psinfo" -ArgumentList "-h -s -d" -Description "System information"
342+
Invoke-Tool -ToolName "clockres" -Description "Clock resolution"
342343

343344
try {
344345
$os = Get-CimInstance Win32_OperatingSystem -ErrorAction Stop
@@ -364,7 +365,7 @@ RAM: $([math]::Round($cs.TotalPhysicalMemory/1GB,2)) GB
364365
# Test: CPU
365366
function Test-CPU {
366367
Write-Host "`n=== CPU Testing ===" -ForegroundColor Green
367-
Run-Tool -ToolName "coreinfo" -Args "-v -f -c" -Description "CPU architecture"
368+
Invoke-Tool -ToolName "coreinfo" -ArgumentList "-v -f -c" -Description "CPU architecture"
368369

369370
try {
370371
$cpu = Get-CimInstance Win32_Processor -ErrorAction Stop | Select-Object -First 1
@@ -458,7 +459,7 @@ function Test-Storage {
458459
Write-Host "Error getting storage info" -ForegroundColor Red
459460
}
460461

461-
Run-Tool -ToolName "du" -Args "-l 2 C:\" -Description "Disk usage C:"
462+
Invoke-Tool -ToolName "du" -ArgumentList "-l 2 C:\" -Description "Disk usage C:"
462463

463464
# Disk performance test
464465
Write-Host "Running disk test..." -ForegroundColor Yellow
@@ -473,7 +474,7 @@ function Test-Storage {
473474
$writeTime = ((Get-Date) - $writeStart).TotalMilliseconds
474475

475476
$readStart = Get-Date
476-
$content = Get-Content $testFile -Raw -ErrorAction Stop
477+
$null = Get-Content $testFile -Raw -ErrorAction Stop
477478
$readTime = ((Get-Date) - $readStart).TotalMilliseconds
478479

479480
Remove-Item $testFile -ErrorAction Stop
@@ -494,14 +495,14 @@ function Test-Storage {
494495
# Test: Processes
495496
function Test-Processes {
496497
Write-Host "`n=== Process Analysis ===" -ForegroundColor Green
497-
Run-Tool -ToolName "pslist" -Args "-t" -Description "Process tree"
498-
Run-Tool -ToolName "handle" -Args "-p explorer" -Description "Explorer handles"
498+
Invoke-Tool -ToolName "pslist" -ArgumentList "-t" -Description "Process tree"
499+
Invoke-Tool -ToolName "handle" -ArgumentList "-p explorer" -Description "Explorer handles"
499500
}
500501

501502
# Test: Security
502503
function Test-Security {
503504
Write-Host "`n=== Security Analysis ===" -ForegroundColor Green
504-
Run-Tool -ToolName "autorunsc" -Args "-a -c" -Description "Autorun entries" -RequiresAdmin $true
505+
Invoke-Tool -ToolName "autorunsc" -ArgumentList "-a -c" -Description "Autorun entries" -RequiresAdmin $true
505506
}
506507

507508
# Test: Network
@@ -611,9 +612,9 @@ function Test-NetworkLatency {
611612
try {
612613
$pspingPath = Join-Path $SysinternalsPath "psping.exe"
613614
if (Test-Path $pspingPath) {
614-
$args = @("-accepteula", "-n", "5", "{0}:{1}" -f $targetHost, $targetPort)
615+
$pspingArgs = @("-accepteula", "-n", "5", "{0}:{1}" -f $targetHost, $targetPort)
615616
Write-Host "Running PsPing latency test..." -ForegroundColor Yellow
616-
$pspingOutput = & $pspingPath $args 2>&1 | Out-String
617+
$pspingOutput = & $pspingPath $pspingArgs 2>&1 | Out-String
617618
$lines += "PsPing Summary:"
618619

619620
$average = $null
@@ -627,7 +628,7 @@ function Test-NetworkLatency {
627628
}
628629
}
629630

630-
if ($average -ne $null) {
631+
if ($null -ne $average) {
631632
$lines += " Min: $minimum ms"
632633
$lines += " Max: $maximum ms"
633634
$lines += " Avg: $average ms"
@@ -1298,7 +1299,7 @@ function Test-WindowsUpdate {
12981299

12991300
# Generate Dual Reports (Clean + Detailed) - ENHANCED VERSION
13001301
# Replace the entire Generate-Report function in SystemTester.ps1 (around line 1260)
1301-
function Generate-Report {
1302+
function New-Report {
13021303
Write-Host "`nGenerating reports..." -ForegroundColor Cyan
13031304

13041305
# Test write access
@@ -1737,9 +1738,14 @@ function Show-Menu {
17371738
Write-Host "10. SSD TRIM Status"
17381739
Write-Host "11. Network Adapters"
17391740
Write-Host "12. GPU (Enhanced)" -ForegroundColor Cyan
1741+
<#
17401742
Write-Host " └─ 12a. Basic GPU Info"
17411743
Write-Host " └─ 12b. Vendor-Specific (NVIDIA/AMD)"
17421744
Write-Host " └─ 12c. GPU Memory Test"
1745+
#>
1746+
Write-Host " - 12a. Basic GPU Info"
1747+
Write-Host " - 12b. Vendor-Specific (NVIDIA/AMD)"
1748+
Write-Host " - 12c. GPU Memory Test"
17431749
Write-Host "13. Power/Battery"
17441750
Write-Host "14. Hardware Events (WHEA)"
17451751
Write-Host "15. Windows Update"
@@ -1802,7 +1808,7 @@ function Start-Menu {
18021808
Write-Host "`nAll tests complete!" -ForegroundColor Green
18031809
Read-Host "Press Enter"
18041810
}
1805-
"17" { Generate-Report; Read-Host "`nPress Enter" }
1811+
"17" { New-Report; Read-Host "`nPress Enter" }
18061812
"18" { $script:TestResults = @(); Write-Host "Cleared" -ForegroundColor Green; Start-Sleep 1 }
18071813
"Q" { return }
18081814
"q" { return }
@@ -1833,7 +1839,7 @@ if ($MyInvocation.InvocationName -ne '.') {
18331839
Test-StorageSMART; Test-Trim; Test-NIC
18341840
Test-GPU; Test-GPUVendorSpecific; Test-GPUMemory
18351841
Test-Power; Test-HardwareEvents; Test-WindowsUpdate
1836-
Generate-Report
1842+
New-Report
18371843
Write-Host "`nAuto-run complete!" -ForegroundColor Green
18381844
Read-Host "Press Enter to exit"
18391845
} else {

0 commit comments

Comments
 (0)