-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork-DetailedDiagnostics.ps1
More file actions
528 lines (449 loc) · 22.8 KB
/
Network-DetailedDiagnostics.ps1
File metadata and controls
528 lines (449 loc) · 22.8 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
<#
.SYNOPSIS
Comprehensive network diagnostics and connectivity analysis tool.
.DESCRIPTION
This script provides detailed network diagnostic information including:
- Complete DNS resolution details and reverse lookups
- Network interface configuration and routing information
- Ping statistics with detailed timing
- Port connectivity with full connection details
- IPSec rules and network isolation context
- Source/destination address mapping
- Network adapter and interface analysis
This complements the basic Network-testAport.ps1 script by providing
the full technical details needed for advanced network troubleshooting.
.PARAMETER Address
The IP address or hostname to analyze.
.PARAMETER Port
Optional port number for TCP connectivity testing.
.PARAMETER IncludePing
Include detailed ping statistics and timing analysis.
.PARAMETER ShowRouting
Display detailed routing table information.
.EXAMPLES
# Full diagnostic of a host
.\Network-DetailedDiagnostics.ps1 -Address "google.com"
# Detailed analysis with port testing
.\Network-DetailedDiagnostics.ps1 -Address "database.company.com" -Port 3306
# Complete analysis with ping and routing
.\Network-DetailedDiagnostics.ps1 -Address "192.168.1.1" -IncludePing -ShowRouting
.OUTPUTS
Comprehensive network analysis report including:
- DNS resolution and reverse lookup results
- Network interface and adapter information
- Routing table entries and gateway information
- IPSec policies and network isolation context
- Ping statistics and latency analysis
- TCP port connectivity details
.NOTES
- Requires PowerShell 4.0 or later
- Some features require elevated privileges
- Designed for detailed network troubleshooting
- Complements the basic port testing script
- Provides full Test-NetConnection output and analysis
.AUTHOR
Mike Brown
.VERSION
1.0
.DATE
2025-10-10
#>
param(
[Parameter(Mandatory=$false)]
[string]$Address,
[Parameter(Mandatory=$false)]
[int]$Port,
[Parameter(Mandatory=$false)]
[switch]$IncludePing,
[Parameter(Mandatory=$false)]
[switch]$ShowRouting
)
function Get-QuickNetworkHealth {
[CmdletBinding()]
param()
Write-Host "=== Network Health Dashboard ===" -ForegroundColor Cyan
Write-Host "Quick assessment of local network connectivity" -ForegroundColor Gray
Write-Host "Timestamp: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor DarkGray
Write-Host ""
# Initialize health tracking
$healthResults = @()
$overallHealthy = $true
# Define test targets with better descriptions
$testTargets = @(
@{ Name = "Gateway"; Description = "Router/Default Gateway"; Address = $null; Critical = $true }
@{ Name = "DNS Server"; Description = "Primary DNS Resolution"; Address = $null; Critical = $true }
@{ Name = "Internet"; Description = "Internet Connectivity"; Address = "8.8.8.8"; Critical = $true }
@{ Name = "External DNS"; Description = "External Name Resolution"; Address = "google.com"; Critical = $false }
)
# Get gateway and DNS server dynamically
try {
$gateway = (Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -First 1).NextHop
$testTargets[0].Address = $gateway
} catch {
$testTargets[0].Address = $null
}
try {
$dnsServer = (Get-DnsClientServerAddress -AddressFamily IPv4 | Where-Object { $_.ServerAddresses.Count -gt 0 } | Select-Object -First 1).ServerAddresses[0]
$testTargets[1].Address = $dnsServer
} catch {
$testTargets[1].Address = $null
}
# Quick health check table header
Write-Host "Network Component Status:" -ForegroundColor Yellow
Write-Host ("{0,-20} {1,-8} {2,-10} {3}" -f "Component", "Status", "Response", "Details") -ForegroundColor Gray
Write-Host ("-" * 60) -ForegroundColor DarkGray
foreach ($target in $testTargets) {
if (-not $target.Address) {
$status = "MISSING"
$responseTime = "N/A"
$details = "Could not determine address"
$statusColor = "Red"
if ($target.Critical) { $overallHealthy = $false }
} else {
try {
# Quick ping test only
$pingResult = Test-NetConnection -ComputerName $target.Address -InformationLevel Quiet -WarningAction SilentlyContinue
if ($pingResult) { # -InformationLevel Quiet returns boolean, not object with .PingSucceeded
$status = "HEALTHY"
$statusColor = "Green"
# Get response time for successful pings
try {
$pingDetails = Test-NetConnection -ComputerName $target.Address -WarningAction SilentlyContinue
if ($pingDetails.PingReplyDetails) {
$responseTime = "$($pingDetails.PingReplyDetails.RoundtripTime)ms"
} else {
$responseTime = "<1ms"
}
} catch {
$responseTime = "SUCCESS"
}
$details = $target.Address
} else {
$status = "FAILED"
$statusColor = "Red"
$responseTime = "TIMEOUT"
$details = "$($target.Address) - Not responding"
if ($target.Critical) { $overallHealthy = $false }
}
} catch {
$status = "ERROR"
$statusColor = "Red"
$responseTime = "ERROR"
$details = "Test failed: $($_.Exception.Message)"
if ($target.Critical) { $overallHealthy = $false }
}
}
# Display result in table format
Write-Host ("{0,-20} " -f $target.Description) -NoNewline
Write-Host ("{0,-8} " -f $status) -NoNewline -ForegroundColor $statusColor
Write-Host ("{0,-10} " -f $responseTime) -NoNewline -ForegroundColor Gray
Write-Host $details -ForegroundColor Gray
# Store result for detailed analysis if needed
$healthResults += @{
Name = $target.Name
Description = $target.Description
Address = $target.Address
Status = $status
ResponseTime = $responseTime
Details = $details
Critical = $target.Critical
Success = ($status -eq "HEALTHY")
}
}
Write-Host ""
# Overall health assessment
if ($overallHealthy) {
Write-Host "[NETWORK HEALTH: EXCELLENT] " -NoNewline -ForegroundColor Green
Write-Host "All critical network components are functioning properly" -ForegroundColor White
} else {
Write-Host "[NETWORK HEALTH: ISSUES DETECTED] " -NoNewline -ForegroundColor Red
Write-Host "One or more critical network components have problems" -ForegroundColor White
# Show failed critical components
$failedCritical = $healthResults | Where-Object { $_.Critical -and -not $_.Success }
if ($failedCritical.Count -gt 0) {
Write-Host "`nCritical Issues:" -ForegroundColor Red
foreach ($failed in $failedCritical) {
Write-Host " * $($failed.Description): $($failed.Details)" -ForegroundColor Yellow
}
}
}
# Network interfaces summary (concise)
Write-Host "`nActive Network Interfaces:" -ForegroundColor Yellow
try {
$interfaces = Get-NetAdapter | Where-Object { $_.Status -eq "Up" -and $_.Virtual -eq $false }
if ($interfaces.Count -eq 0) {
$interfaces = Get-NetAdapter | Where-Object { $_.Status -eq "Up" } | Select-Object -First 2
}
foreach ($interface in $interfaces) {
$ipConfig = Get-NetIPAddress -InterfaceIndex $interface.InterfaceIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue
if ($ipConfig) {
$speed = if ($interface.LinkSpeed -ge 1GB) { "$([math]::Round($interface.LinkSpeed / 1GB, 1)) Gbps" } else { "$([math]::Round($interface.LinkSpeed / 1MB, 0)) Mbps" }
Write-Host " * $($interface.Name): $($ipConfig.IPAddress) ($speed)" -ForegroundColor Gray
}
}
} catch {
Write-Host " Could not retrieve interface information" -ForegroundColor Red
}
# Quick recommendations
Write-Host "`nQuick Actions:" -ForegroundColor Yellow
if ($overallHealthy) {
Write-Host " * Network is healthy - no action needed" -ForegroundColor Green
Write-Host " * For specific port testing: .\Network-testAport.ps1" -ForegroundColor Gray
Write-Host " * For detailed analysis: .\Network-DetailedDiagnostics.ps1 -Address <target>" -ForegroundColor Gray
} else {
Write-Host " * Check physical network connections" -ForegroundColor White
Write-Host " * Restart router/modem if gateway is unreachable" -ForegroundColor White
Write-Host " * Check DNS settings if DNS resolution fails" -ForegroundColor White
Write-Host " * For detailed troubleshooting: Run this script in mode 2" -ForegroundColor Cyan
Write-Host " * For DNS cleanup: Run .\Network-FixDns.ps1" -ForegroundColor Yellow
}
return $healthResults
}
function Get-DetailedNetworkDiagnostics {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$TargetAddress,
[Parameter(Mandatory=$false)]
[int]$TargetPort,
[Parameter(Mandatory=$false)]
[switch]$IncludePingStats,
[Parameter(Mandatory=$false)]
[switch]$ShowRoutingInfo
)
Write-Host "=== Detailed Network Analysis ===" -ForegroundColor Cyan
Write-Host "Target: $TargetAddress" -ForegroundColor White
if ($TargetPort) {
Write-Host "Port: $TargetPort" -ForegroundColor White
}
Write-Host "Timestamp: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Gray
Write-Host ""
# Basic connectivity test
Write-Host "=== Connectivity Test ===" -ForegroundColor Green
try {
if ($TargetPort) {
$result = Test-NetConnection -ComputerName $TargetAddress -Port $TargetPort -InformationLevel Detailed -WarningAction SilentlyContinue
} else {
$result = Test-NetConnection -ComputerName $TargetAddress -InformationLevel Detailed -WarningAction SilentlyContinue
}
Write-Host "Connection Status: $(if ($result.PingSucceeded) { 'SUCCESS' } else { 'FAILED' })" -ForegroundColor $(if ($result.PingSucceeded) { 'Green' } else { 'Red' })
if ($TargetPort) {
Write-Host "Port Status: $(if ($result.TcpTestSucceeded) { 'OPEN' } else { 'CLOSED/FILTERED' })" -ForegroundColor $(if ($result.TcpTestSucceeded) { 'Green' } else { 'Red' })
}
} catch {
Write-Host "Connection test failed: $($_.Exception.Message)" -ForegroundColor Red
return
}
# DNS Resolution Analysis
Write-Host "`n=== DNS Resolution Analysis ===" -ForegroundColor Green
Write-Host "Resolved IP Address: $($result.RemoteAddress)" -ForegroundColor White
if ($result.NameResolutionResults -and $result.NameResolutionResults.Count -gt 1) {
Write-Host "`nAdditional DNS Results:" -ForegroundColor Yellow
$result.NameResolutionResults | Select-Object -Skip 1 | ForEach-Object {
Write-Host " $($_)" -ForegroundColor Gray
}
}
# Network Interface Information
Write-Host "`n=== Network Path Information ===" -ForegroundColor Green
Write-Host "Source Address: $($result.SourceAddress.IPAddress)" -ForegroundColor White
Write-Host "Network Interface: $($result.InterfaceAlias)" -ForegroundColor White
Write-Host "Network Context: $($result.NetworkIsolationContext)" -ForegroundColor White
if ($result.NetRoute) {
Write-Host "Next Hop (Gateway): $($result.NetRoute.NextHop)" -ForegroundColor White
}
# Ping Statistics
if ($IncludePingStats -or $result.PingSucceeded) {
Write-Host "`n=== Ping Analysis ===" -ForegroundColor Green
if ($result.PingSucceeded) {
Write-Host "Ping Status: SUCCESS" -ForegroundColor Green
if ($result.PingReplyDetails) {
Write-Host "Round Trip Time: $($result.PingReplyDetails.RoundtripTime) ms" -ForegroundColor White
Write-Host "Status: $($result.PingReplyDetails.Status)" -ForegroundColor White
}
} else {
Write-Host "Ping Status: FAILED" -ForegroundColor Red
Write-Host "Note: Host may block ICMP or be unreachable" -ForegroundColor Yellow
}
}
# Port-specific information
if ($TargetPort) {
Write-Host "`n=== Port Analysis ===" -ForegroundColor Green
Write-Host "Target Port: $($result.RemotePort)" -ForegroundColor White
Write-Host "TCP Test Result: $(if ($result.TcpTestSucceeded) { 'SUCCESS' } else { 'FAILED' })" -ForegroundColor $(if ($result.TcpTestSucceeded) { 'Green' } else { 'Red' })
# Service identification
$commonServices = @{
22 = "SSH"; 23 = "Telnet"; 25 = "SMTP"; 53 = "DNS"; 80 = "HTTP"
110 = "POP3"; 443 = "HTTPS"; 445 = "SMB"; 587 = "SMTP Secure"
993 = "IMAP"; 995 = "POP3 Secure"; 1433 = "SQL Server"; 2181 = "Zookeeper"
3306 = "MySQL"; 3389 = "RDP"; 5432 = "PostgreSQL"; 5601 = "Kibana"
5672 = "RabbitMQ"; 6379 = "Redis"; 9092 = "Kafka"; 9200 = "Elasticsearch"
9999 = "Kafka JMX"; 15672 = "RabbitMQ Management"; 27017 = "MongoDB"
}
if ($commonServices.ContainsKey($TargetPort)) {
Write-Host "Service Type: $($commonServices[$TargetPort])" -ForegroundColor Cyan
}
}
# Administrative context
Write-Host "`n=== System Context ===" -ForegroundColor Green
Write-Host "Running as Admin: $(if ($result.IsAdmin) { 'YES' } else { 'NO' })" -ForegroundColor $(if ($result.IsAdmin) { 'Green' } else { 'Yellow' })
# Routing information (if requested)
if ($ShowRoutingInfo) {
Write-Host "`n=== Routing Information ===" -ForegroundColor Green
try {
$routes = Get-NetRoute | Where-Object { $_.DestinationPrefix -eq "0.0.0.0/0" -or $_.DestinationPrefix -like "*$($result.RemoteAddress)*" } | Select-Object -First 5
if ($routes) {
$routes | Format-Table DestinationPrefix, NextHop, InterfaceAlias, RouteMetric -AutoSize | Out-Host
} else {
Write-Host "No specific routes found for target" -ForegroundColor Yellow
}
} catch {
Write-Host "Could not retrieve routing information: $($_.Exception.Message)" -ForegroundColor Red
}
}
# Summary and recommendations
Write-Host "`n=== Analysis Summary ===" -ForegroundColor Green
if ($result.PingSucceeded) {
Write-Host "[SUCCESS] Host is reachable" -ForegroundColor Green
} else {
Write-Host "[FAILED] Host is not responding to ping" -ForegroundColor Red
Write-Host " - Check if host is online" -ForegroundColor Yellow
Write-Host " - Verify firewall settings" -ForegroundColor Yellow
Write-Host " - Check network connectivity" -ForegroundColor Yellow
}
if ($TargetPort) {
if ($result.TcpTestSucceeded) {
Write-Host "[SUCCESS] Port $TargetPort is accessible" -ForegroundColor Green
} else {
Write-Host "[FAILED] Port $TargetPort is not accessible" -ForegroundColor Red
Write-Host " - Verify service is running" -ForegroundColor Yellow
Write-Host " - Check port-specific firewall rules" -ForegroundColor Yellow
Write-Host " - Confirm correct port number" -ForegroundColor Yellow
}
}
# Create cleaner output object instead of returning raw Test-NetConnection result
Write-Host ""
$cleanOutput = [PSCustomObject]@{
Target = $TargetAddress
TargetResolved = $result.RemoteAddress
SourceAddress = $result.SourceAddress.IPAddress
NetworkInterface = $result.InterfaceAlias
Gateway = if ($result.NetRoute) { $result.NetRoute.NextHop } else { "N/A" }
PingSuccess = $result.PingSucceeded
ResponseTime = if ($result.PingReplyDetails) { "$($result.PingReplyDetails.RoundtripTime) ms" } else { "0 ms" }
}
if ($TargetPort) {
$cleanOutput | Add-Member -MemberType NoteProperty -Name "PortStatus" -Value $(if ($result.TcpTestSucceeded) { "OPEN" } else { "CLOSED" })
$cleanOutput | Add-Member -MemberType NoteProperty -Name "Port" -Value $TargetPort
}
$cleanOutput | Format-List
return $cleanOutput
}
# Main execution
if (-not $Address) {
Write-Host "=== Network Environment Diagnostics ===" -ForegroundColor Cyan
Write-Host "Choose diagnostic mode:" -ForegroundColor Yellow
Write-Host "1. Quick Health Check (default) - See if your network is working" -ForegroundColor White
Write-Host "2. Analyze Specific Target - Deep dive into one IP/website" -ForegroundColor White
Write-Host "3. Full Report - Health check + details on any problems" -ForegroundColor White
Write-Host "H. Help - Explain what each option does" -ForegroundColor Gray
Write-Host ""
$mode = Read-Host "Enter choice (1, 2, 3, or H, default: 1)"
if ($mode -match '^[Hh]') {
# Help menu
Write-Host ""
Write-Host "=== HELP - What Each Option Does ===" -ForegroundColor Cyan
Write-Host ""
Write-Host "1. Quick Health Check" -ForegroundColor Green
Write-Host " - Tests your router, internet, and DNS in seconds" -ForegroundColor White
Write-Host " - Shows simple HEALTHY/FAILED status for each" -ForegroundColor White
Write-Host " - Perfect for: 'Is my network working?'" -ForegroundColor Gray
Write-Host " - Takes: ~10 seconds" -ForegroundColor Gray
Write-Host ""
Write-Host "2. Analyze Specific Target" -ForegroundColor Green
Write-Host " - Deep analysis of ONE specific IP address or website" -ForegroundColor White
Write-Host " - Shows detailed connection paths, ping times, DNS info" -ForegroundColor White
Write-Host " - Perfect for: 'Why can't I reach google.com?'" -ForegroundColor Gray
Write-Host " - Takes: ~30 seconds per target" -ForegroundColor Gray
Write-Host ""
Write-Host "3. Full Report" -ForegroundColor Green
Write-Host " - Combines options 1 + 2: Quick overview first" -ForegroundColor White
Write-Host " - Then automatically analyzes any problems found" -ForegroundColor White
Write-Host " - Perfect for: 'Check everything and fix problems'" -ForegroundColor Gray
Write-Host " - Takes: ~10 seconds + extra time for problems" -ForegroundColor Gray
Write-Host ""
Write-Host "Examples:" -ForegroundColor Yellow
Write-Host "- Network seems slow → Choose 1 (Quick Check)" -ForegroundColor White
Write-Host "- Can't reach a specific website → Choose 2 (Specific Target)" -ForegroundColor White
Write-Host "- Want full network troubleshooting → Choose 3 (Full Report)" -ForegroundColor White
Write-Host "- DNS issues detected → Run .\Network-FixDns.ps1 separately" -ForegroundColor White
Write-Host ""
$choice = Read-Host "Now choose your option (1, 2, or 3)"
$mode = $choice
}
if ($mode -eq "2") {
# Detailed analysis mode only
Write-Host ""
$Address = Read-Host "Enter IP address or hostname for detailed analysis"
if ([string]::IsNullOrWhiteSpace($Address)) {
Write-Host "Address is required for detailed analysis" -ForegroundColor Red
exit 1
}
Write-Host "`nNote: For port connectivity testing, use Network-testAport.ps1" -ForegroundColor Yellow
$pingChoice = Read-Host "Include detailed ping analysis? (Y/N, default: Y)"
if ($pingChoice -notmatch '^[Nn]') {
$IncludePing = $true
}
$routeChoice = Read-Host "Show routing table information? (Y/N, default: N)"
if ($routeChoice -match '^[Yy]') {
$ShowRouting = $true
}
} elseif ($mode -eq "3") {
# Combined mode - quick health + detailed analysis of failures
Write-Host ""
$healthResults = Get-QuickNetworkHealth
# Automatically analyze failed components
$failedComponents = $healthResults | Where-Object { -not $_.Success -and $_.Address }
if ($failedComponents.Count -gt 0) {
Write-Host "`n" + ("="*70) -ForegroundColor Cyan
Write-Host "DETAILED ANALYSIS OF FAILED COMPONENTS" -ForegroundColor Cyan
Write-Host ("="*70) -ForegroundColor Cyan
foreach ($failed in $failedComponents) {
Write-Host "`n" + ("-"*60) -ForegroundColor DarkGray
Write-Host "Analyzing: $($failed.Description)" -ForegroundColor Yellow
Write-Host ("-"*60) -ForegroundColor DarkGray
try {
Get-DetailedNetworkDiagnostics -TargetAddress $failed.Address -IncludePingStats:$true
} catch {
Write-Host "Failed to perform detailed analysis: $($_.Exception.Message)" -ForegroundColor Red
}
}
} else {
Write-Host "`n[ALL SYSTEMS HEALTHY] No failed components found for detailed analysis" -ForegroundColor Green
}
Write-Host "`n=== Network Health Check Complete ===" -ForegroundColor Cyan
return
} else {
# Quick health check mode only (default)
Write-Host ""
$null = Get-QuickNetworkHealth # Suppress return output
Write-Host "`n=== Quick Health Check Complete ===" -ForegroundColor Cyan
Write-Host "Tip: Use mode 2 for detailed analysis of specific targets" -ForegroundColor Gray
Write-Host "Tip: Use mode 3 for automatic detailed analysis of any failures" -ForegroundColor Gray
return
}
}
# Run the detailed diagnostics
try {
$result = Get-DetailedNetworkDiagnostics -TargetAddress $Address -TargetPort $Port -IncludePingStats:$IncludePing -ShowRoutingInfo:$ShowRouting
Write-Host "`n=== Diagnostics Complete ===" -ForegroundColor Cyan
Write-Host "For basic port testing, use Network-testAport.ps1" -ForegroundColor Gray
} catch {
Write-Host "`nDiagnostics failed: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Stack trace:" -ForegroundColor Yellow
Write-Host $_.ScriptStackTrace -ForegroundColor Yellow
}
# Pause if run directly
if ($Host.Name -eq "ConsoleHost") {
Write-Host "`nPress Enter to close..." -ForegroundColor Gray
Read-Host
}