-
Notifications
You must be signed in to change notification settings - Fork 36
/
Get-NetView.psm1
3035 lines (2484 loc) · 119 KB
/
Get-NetView.psm1
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
$Global:Version = "2024.11.13.242"
$Script:RunspacePool = $null
$Script:ThreadList = [Collections.ArrayList]@()
$Global:QueueActivity = "Queueing tasks..."
$Global:FinishActivity = "Finishing..."
$Global:ChelsioDeviceDirs = @{}
$Global:MellanoxSystemLogDir = ""
$ExecFunctions = {
param(
[parameter(Mandatory=$true)] [Hashtable] $ExecParams
)
$columns = 4096
# Alias Write-CmdLog to Write-Host for background threads,
# since console color only applies to the main thread.
Set-Alias -Name Write-CmdLog -Value Write-Host
<#
.SYNOPSIS
Log control path errors or issues.
#>
function ExecControlError {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [String] $Message
)
$callerName = (Get-PSCallStack)[1].FunctionName
$file = "_Error.$callerName.txt"
$out = Join-Path $OutDir $file
Write-Output $Message | Out-File -Encoding "default" -Width $columns -Append $out
} # ExecControlError()
enum CommandStatus {
NotRun # The command was not executed
Unavailable # [Part of] the command doesn't exist
Failed # An error prevented successful execution
Success # No errors or exceptions
}
# Powershell cmdlets have inconsistent implementations in command error handling. This function
# performs a validation of the command prior to formal execution and will log any failures.
function TestCommand {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $Command
)
$status = [CommandStatus]::NotRun
$duration = [TimeSpan]::Zero
$commandOut = ""
# Check timeout
$delta = (Get-Date) - $ExecParams.StartTime
if ($delta.TotalMinutes -gt $ExecParams.Timeout) {
return $status, $duration.TotalMilliseconds, $commandOut
}
try {
$error.Clear()
# Redirect all command output (expect errors) to stdout.
# Any errors will still be output to $error variable.
$silentCmd = '$({0}) 2>$null 3>&1 4>&1 5>&1 6>&1' -f $Command
$duration = Measure-Command {
# ErrorAction MUST be Stop for try catch to work.
$commandOut = (Invoke-Expression $silentCmd -ErrorAction Stop)
}
# Sometimes commands output errors even on successful execution.
# We only should fail commands if an error was their *only* output.
if (($error -ne $null) -and [String]::IsNullOrWhiteSpace($commandOut)) {
# Some PS commands are incorrectly implemented in return
# code and require detecting SilentlyContinue
if ($Command -notlike "*SilentlyContinue*") {
throw $error[0]
}
}
$status = [CommandStatus]::Success
} catch [Management.Automation.CommandNotFoundException] {
$status = [CommandStatus]::Unavailable
} catch {
$status = [CommandStatus]::Failed
$commandOut = ($_ | Out-String)
} finally {
# Post-execution cleanup to avoid false positives
$error.Clear()
}
return $status, $duration.TotalMilliseconds, $commandOut
} # TestCommand()
function CreateZip {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $Src,
[parameter(Mandatory=$true)] [String] $Out
)
if (Test-path $Out) {
Remove-item $Out
}
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($Src, $Out)
} # CreateZip()
function ExecCommand {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $Command
)
$status, [Int] $duration, $commandOut = TestCommand -Command $Command
# Mirror command execution context
Write-Output "$env:USERNAME @ ${env:COMPUTERNAME}:"
# Mirror command to execute
Write-Output "$(prompt)$Command"
$logPrefix = "({0,6:n0} ms)" -f $duration
if ($status -ne [CommandStatus]::Success) {
$logPrefix = "$logPrefix [$status]"
Write-Output "[$status]"
}
Write-Output $commandOut
Write-CmdLog "$logPrefix $Command"
if ($ExecParams.DelayFactor -gt 0) {
Start-Sleep -Milliseconds ($duration * $ExecParams.DelayFactor + 0.50) # round up
}
} # ExecCommand()
function ExecCommands {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $File,
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [String[]] $Commands
)
$out = (Join-Path -Path $OutDir -ChildPath $File)
$($Commands | foreach {ExecCommand -Command $_}) | Out-File -Encoding "default" -Width $columns -Append $out
# With high-concurreny, WMI-based cmdlets sometimes output in an
# incorrect format or with missing fields. Somehow, this helps
# reduce the frequency of the problem.
$null = Get-NetAdapter
} # ExecCommands()
} # $ExecFunctions
<#
.SYNOPSIS
Create a shortcut file (.LNK) pointing to $TargetPath.
.NOTES
Used to avoid duplicate effort in IHV commands, which are
executed per NIC, but some data is per system/ASIC.
#>
function New-LnkShortcut {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $LnkFile,
[parameter(Mandatory=$true)] [String] $TargetPath
)
if ($LnkFile -notlike "*.lnk") {
return
}
$shell = New-Object -ComObject "WScript.Shell"
$lnk = $shell.CreateShortcut($LnkFile)
$lnk.TargetPath = $TargetPath
$null = $lnk.Save()
$null = [Runtime.Interopservices.Marshal]::ReleaseComObject($shell)
} # New-LnkShortcut()
<#
.SYNOPSIS
Replaces invalid characters with a placeholder to make a
valid directory or filename.
.NOTES
Do not pass in a path. It will replace '\' and '/'.
#>
function ConvertTo-Filename {
[CmdletBinding()]
Param(
[parameter(Position=0, Mandatory=$true)] [String] $Filename
)
$invalidChars = [System.IO.Path]::GetInvalidFileNameChars() -join ""
return $Filename -replace "[$invalidChars]","_"
}
function TryCmd {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [ScriptBlock] $ScriptBlock
)
try {
$out = &$ScriptBlock
} catch {
$out = $null
}
# Returning $null will cause foreach to iterate once
# unless TryCmd call is in parentheses.
if ($out -eq $null) {
$out = @()
}
return $out
} # TryCmd()
function Write-CmdLog {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $CmdLog
)
$logColor = [ConsoleColor]::White
switch -Wildcard ($CmdLog) {
"*``[Failed``]*" {
$logColor = [ConsoleColor]::Yellow
break
}
"*``[Unavailable``]*" {
$logColor = [ConsoleColor]::DarkGray
break
}
"*``[NotRun``]*" {
$logColor = [ConsoleColor]::Gray
break
}
}
Write-Host $CmdLog -ForegroundColor $logColor
} # Write-CmdLog()
function Open-GlobalRunspacePool {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [Int] $BackgroundThreads
)
if ($BackgroundThreads -gt 0) {
$Script:RunspacePool = [RunspaceFactory]::CreateRunspacePool(1, $BackgroundThreads)
$Script:RunspacePool.Open()
}
if ($BackgroundThreads -le 1) {
Set-Alias ExecCommandsAsync ExecCommands
$Global:QueueActivity = "Executing commands..."
}
} # Open-GlobalRunspacePool()
function Close-GlobalRunspacePool {
[CmdletBinding()]
Param()
if ($Script:RunspacePool -ne $null) {
Write-Progress -Activity $Global:FinishActivity -Status "Cleanup background threads..."
if ($Script:ThreadList.Count -gt 0) {
# Kill any DISM child process, which ignores below Stop attempt...
$dismId = @(Get-CimInstance "Win32_Process" -Filter "Name = 'DismHost.exe' AND ParentProcessId = $PID").ProcessId
if ($dismId.Count -gt 0) {
Stop-Process -Id $dismId -Force
}
# Asyncronously stop all threads.
$Script:ThreadList | foreach {
$_.AsyncStop = $_.PowerShell.BeginStop($null, $_.AsyncInvoke)
}
# Wait for stops to complete.
$Script:ThreadList | foreach {
Write-CmdLog "( 0 ms) [NotRun] $($_.Command)"
$_.PowerShell.EndStop($_.AsyncStop)
}
$Script:ThreadList.Clear()
}
$Script:RunspacePool.Close()
$Script:RunspacePool.Dispose()
$Script:RunspacePool = $null
}
} # Close-GlobalRunspacePool()
function Start-Thread {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [ScriptBlock] $ScriptBlock,
[parameter(Mandatory=$false)] [Hashtable] $Params = @{}
)
if ($null -eq $Script:RunspacePool) {
# Execute command synchronously instead
&$ScriptBlock @Params
} else {
$ps = [PowerShell]::Create()
$ps.RunspacePool = $Script:RunspacePool
$null = $ps.AddScript("Set-Location `"$(Get-Location)`"")
$null = $ps.AddScript($ExecFunctions).AddParameter("ExecParams", $Global:ExecParams)
$null = $ps.AddScript($ScriptBlock, $true).AddParameters($Params)
$async = $ps.BeginInvoke()
$cmd = if ($ScriptBlock -eq ${function:ExecCommands}) {$Params.Commands} else {$ScriptBlock.Ast.Name}
$null = $Script:ThreadList.Add(@{AsyncInvoke=$async; Command=$cmd; PowerShell=$ps})
}
} # Start-Thread()
function Show-Threads {
[CmdletBinding()]
Param()
$totalTasks = $Script:ThreadList.Count
while ($Script:ThreadList.Count -gt 0) {
Write-Progress -Activity "Waiting for all tasks to complete..." -Status "$($Script:ThreadList.Count) remaining." -PercentComplete (100 * (1 - $Script:ThreadList.Count / $totalTasks))
for ($i = 0; $i -lt $Script:ThreadList.Count; $i++) {
$thread = $Script:ThreadList[$i]
$thread.Powershell.Streams.Warning | Out-Host
$thread.Powershell.Streams.Warning.Clear()
$thread.Powershell.Streams.Information | foreach {Write-CmdLog "$_"}
$thread.Powershell.Streams.Information.Clear()
if ($thread.AsyncInvoke.IsCompleted) {
# Accessing Streams.Error blocks until thread is completed
$thread.Powershell.Streams.Error | Out-Host
$thread.Powershell.Streams.Error.Clear()
$thread.PowerShell.EndInvoke($thread.AsyncInvoke)
$Script:ThreadList.RemoveAt($i)
$i--
}
}
$delta = (Get-Date) - $Global:ExecParams.StartTime
if ($delta.TotalMinutes -gt $Global:ExecParams.Timeout) {
Write-Warning "Timeout was reached."
break
}
Start-Sleep -Milliseconds 33 # ~30 Hz
}
} # Show-Threads()
function ExecCommandsAsync {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [String] $File,
[parameter(Mandatory=$true)] [String[]] $Commands
)
return Start-Thread -ScriptBlock ${function:ExecCommands} -Params $PSBoundParameters
} # ExecCommandsAsync()
function ExecCopyItemsAsync {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir,
[parameter(Mandatory=$true)] [String] $File,
[parameter(Mandatory=$true)] [String[]] $Paths,
[parameter(Mandatory=$true)] [String] $Destination
)
if (-not (Test-Path $Destination)) {
$null = New-Item -ItemType "Container" -Path $Destination
}
[String[]] $cmds = $Paths | foreach {"Copy-Item -Path ""$_"" -Destination ""$Destination"" -Recurse -Verbose 4>&1"}
return ExecCommandsAsync -OutDir $OutDir -File $File -Commands $cmds
} # ExecCopyItemsAsync()
#
# Data Collection Functions
#
function NetIpNic {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$name = $NicName
$dir = (Join-Path -Path $OutDir -ChildPath "NetIp")
New-Item -ItemType directory -Path $dir | Out-Null
$file = "Get-NetIpAddress.txt"
[String []] $cmds = "Get-NetIpAddress -InterfaceAlias ""$name"" | Format-Table -AutoSize",
"Get-NetIpAddress -InterfaceAlias ""$name"" | Format-Table -Property * -AutoSize",
"Get-NetIpAddress -InterfaceAlias ""$name"" | Format-List",
"Get-NetIpAddress -InterfaceAlias ""$name"" | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetIPInterface.txt"
[String []] $cmds = "Get-NetIPInterface -InterfaceAlias ""$name""",
"Get-NetIPInterface -InterfaceAlias ""$name"" | Format-Table -AutoSize",
"Get-NetIPInterface -InterfaceAlias ""$name"" | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNeighbor.txt"
[String []] $cmds = "Get-NetNeighbor -InterfaceAlias ""$name""",
"Get-NetNeighbor -InterfaceAlias ""$name"" | Format-Table -AutoSize",
"Get-NetNeighbor -InterfaceAlias ""$name"" | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetRoute.txt"
[String []] $cmds = "Get-NetRoute -InterfaceAlias ""$name"" | Format-Table -AutoSize",
"Get-NetRoute -InterfaceAlias ""$name"" | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
} # NetIpNic()
function NetIp {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
Write-Progress -Activity $Global:QueueActivity -Status "Processing $($MyInvocation.MyCommand.Name)"
$dir = (Join-Path -Path $OutDir -ChildPath "NetIp")
New-Item -ItemType directory -Path $dir | Out-Null
$file = "Get-NetIpAddress.txt"
[String []] $cmds = "Get-NetIpAddress | Format-Table -AutoSize",
"Get-NetIpAddress | Format-Table -Property * -AutoSize",
"Get-NetIpAddress | Format-List",
"Get-NetIpAddress | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetIPInterface.txt"
[String []] $cmds = "Get-NetIPInterface",
"Get-NetIPInterface | Format-Table -AutoSize",
"Get-NetIPInterface | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNeighbor.txt"
[String []] $cmds = "Get-NetNeighbor | Format-Table -AutoSize",
"Get-NetNeighbor | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetIPv4Protocol.txt"
[String []] $cmds = "Get-NetIPv4Protocol",
"Get-NetIPv4Protocol | Format-List -Property *",
"Get-NetIPv4Protocol | Format-Table -Property * -AutoSize",
"Get-NetIPv4Protocol | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetIPv6Protocol.txt"
[String []] $cmds = "Get-NetIPv6Protocol",
"Get-NetIPv6Protocol | Format-List -Property *",
"Get-NetIPv6Protocol | Format-Table -Property * -AutoSize",
"Get-NetIPv6Protocol | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetOffloadGlobalSetting.txt"
[String []] $cmds = "Get-NetOffloadGlobalSetting",
"Get-NetOffloadGlobalSetting | Format-List -Property *",
"Get-NetOffloadGlobalSetting | Format-Table -AutoSize",
"Get-NetOffloadGlobalSetting | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetPrefixPolicy.txt"
[String []] $cmds = "Get-NetPrefixPolicy | Format-Table -AutoSize",
"Get-NetPrefixPolicy | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetRoute.txt"
[String []] $cmds = "Get-NetRoute | Format-Table -AutoSize",
"Get-NetRoute | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetTCPConnection.txt"
[String []] $cmds = "Get-NetTCPConnection | Format-Table -AutoSize",
"Get-NetTCPConnection | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetTcpSetting.txt"
[String []] $cmds = "Get-NetTcpSetting | Format-Table -AutoSize",
"Get-NetTcpSetting | Format-Table -Property * -AutoSize",
"Get-NetTcpSetting | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetTransportFilter.txt"
[String []] $cmds = "Get-NetTransportFilter | Format-Table -AutoSize",
"Get-NetTransportFilter | Format-Table -Property * -AutoSize",
"Get-NetTransportFilter | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetUDPEndpoint.txt"
[String []] $cmds = "Get-NetUDPEndpoint | Format-Table -AutoSize",
"Get-NetUDPEndpoint | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetUDPSetting.txt"
[String []] $cmds = "Get-NetUDPSetting | Format-Table -AutoSize",
"Get-NetUDPSetting | Format-Table -Property * -AutoSize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
} # NetIp()
function NetNatDetail {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
Write-Progress -Activity $Global:QueueActivity -Status "Processing $($MyInvocation.MyCommand.Name)"
$dir = (Join-Path -Path $OutDir -ChildPath "NetNat")
New-Item -ItemType directory -Path $dir | Out-Null
$file = "Get-NetNat.txt"
[String []] $cmds = "Get-NetNat | Format-Table -AutoSize",
"Get-NetNat | Format-Table -Property * -AutoSize",
"Get-NetNat | Format-List",
"Get-NetNat | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNatExternalAddress.txt"
[String []] $cmds = "Get-NetNatExternalAddress | Format-Table -AutoSize",
"Get-NetNatExternalAddress | Format-Table -Property * -AutoSize",
"Get-NetNatExternalAddress | Format-List",
"Get-NetNatExternalAddress | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNatGlobal.txt"
[String []] $cmds = "Get-NetNatGlobal | Format-Table -AutoSize",
"Get-NetNatGlobal | Format-Table -Property * -AutoSize",
"Get-NetNatGlobal | Format-List",
"Get-NetNatGlobal | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNatSession.txt"
[String []] $cmds = "Get-NetNatSession | Format-Table -AutoSize",
"Get-NetNatSession | Format-Table -Property * -AutoSize",
"Get-NetNatSession | Format-List",
"Get-NetNatSession | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetNatStaticMapping.txt"
[String []] $cmds = "Get-NetNatStaticMapping | Format-Table -AutoSize",
"Get-NetNatStaticMapping | Format-Table -Property * -AutoSize",
"Get-NetNatStaticMapping | Format-List",
"Get-NetNatStaticMapping | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
} # NetNat()
function NetAdapterWorker {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$name = $NicName
$dir = $OutDir
$file = "nmbind.txt"
[String []] $cmds = "nmbind ""$name"" "
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapter.txt"
[String []] $cmds = "Get-NetAdapter -Name ""$name"" -IncludeHidden",
"Get-NetAdapter -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterAdvancedProperty.txt"
[String []] $cmds = "Get-NetAdapterAdvancedProperty -Name ""$name"" -AllProperties -IncludeHidden | Sort-Object RegistryKeyword | Format-Table -AutoSize",
"Get-NetAdapterAdvancedProperty -Name ""$name"" -AllProperties -IncludeHidden | Format-List -Property *",
"Get-NetAdapterAdvancedProperty -Name ""$name"" -AllProperties -IncludeHidden | Format-Table -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterBinding.txt"
[String []] $cmds = "Get-NetAdapterBinding -Name ""$name"" -AllBindings -IncludeHidden | Sort-Object ComponentID",
"Get-NetAdapterBinding -Name ""$name"" -AllBindings -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterChecksumOffload.txt"
[String []] $cmds = "Get-NetAdapterChecksumOffload -Name ""$name"" -IncludeHidden",
"Get-NetAdapterChecksumOffload -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterLso.txt"
[String []] $cmds = "Get-NetAdapterLso -Name ""$name"" -IncludeHidden",
"Get-NetAdapterLso -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterRss.txt"
[String []] $cmds = "Get-NetAdapterRss -Name ""$name"" -IncludeHidden",
"Get-NetAdapterRss -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterStatistics.txt"
[String []] $cmds = "Get-NetAdapterStatistics -Name ""$name"" -IncludeHidden",
"Get-NetAdapterStatistics -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterEncapsulatedPacketTaskOffload.txt"
[String []] $cmds = "Get-NetAdapterEncapsulatedPacketTaskOffload -Name ""$name"" -IncludeHidden",
"Get-NetAdapterEncapsulatedPacketTaskOffload -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterHardwareInfo.txt"
[String []] $cmds = "Get-NetAdapterHardwareInfo -Name ""$name"" -IncludeHidden",
"Get-NetAdapterHardwareInfo -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterIPsecOffload.txt"
[String []] $cmds = "Get-NetAdapterIPsecOffload -Name ""$name"" -IncludeHidden",
"Get-NetAdapterIPsecOffload -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterPowerManagement.txt"
[String []] $cmds = "Get-NetAdapterPowerManagement -Name ""$name"" -IncludeHidden",
"Get-NetAdapterPowerManagement -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterQos.txt"
[String []] $cmds = "Get-NetAdapterQos -Name ""$name"" -IncludeHidden",
"Get-NetAdapterQos -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterRdma.txt"
[String []] $cmds = "Get-NetAdapterRdma -Name ""$name"" -IncludeHidden",
"Get-NetAdapterRdma -Name ""$name"" -IncludeHidden | Format-List -Property *",
"Get-NetAdapterRdma -Name ""$name"" -IncludeHidden | Select-Object -ExpandProperty RdmaAdapterInfo",
"Get-NetAdapterRdma -Name ""$name"" -IncludeHidden | Select-Object -ExpandProperty RdmaMissingCounterInfo"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterPacketDirect.txt"
[String []] $cmds = "Get-NetAdapterPacketDirect -Name ""$name"" -IncludeHidden",
"Get-NetAdapterPacketDirect -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterRsc.txt"
[String []] $cmds = "Get-NetAdapterRsc -Name ""$name"" -IncludeHidden",
"Get-NetAdapterRsc -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterSriov.txt"
[String []] $cmds = "Get-NetAdapterSriov -Name ""$name"" -IncludeHidden",
"Get-NetAdapterSriov -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterSriovVf.txt"
[String []] $cmds = "Get-NetAdapterSriovVf -Name ""$name"" -IncludeHidden",
"Get-NetAdapterSriovVf -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterUso.txt"
[String []] $cmds = "Get-NetAdapterUso -Name ""$name"" -IncludeHidden",
"Get-NetAdapterUso -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterVmq.txt"
[String []] $cmds = "Get-NetAdapterVmq -Name ""$name"" -IncludeHidden",
"Get-NetAdapterVmq -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterVmqQueue.txt"
[String []] $cmds = "Get-NetAdapterVmqQueue -Name ""$name"" -IncludeHidden",
"Get-NetAdapterVmqQueue -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetAdapterVPort.txt"
[String []] $cmds = "Get-NetAdapterVPort -Name ""$name"" -IncludeHidden",
"Get-NetAdapterVPort -Name ""$name"" -IncludeHidden | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
} # NetAdapterWorker()
function NetAdapterWorkerPrepare {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[ValidateSet("pNIC", "hNIC", "NIC")]
[parameter(Mandatory=$true)] [String] $Type,
[parameter(Mandatory=$true)] [String] $OutDir
)
$name = $NicName
$dir = $OutDir
$script:NetAdapterTracker += $nic.ifIndex
# Create dir for each NIC
$nic = Get-NetAdapter -Name $name -IncludeHidden
$idx = $nic.InterfaceIndex
$desc = $nic.InterfaceDescription
$title = "$Type.$idx.$name"
if ("$desc") {
$title = "$title.$desc"
}
if ($nic.Hidden) {
$dir = Join-Path $dir "NIC.Hidden"
}
$dir = Join-Path $dir $(ConvertTo-Filename $title.Trim())
New-Item -ItemType directory -Path $dir | Out-Null
Write-Progress $Global:QueueActivity -Status "Processing $title"
NetIpNic -NicName $name -OutDir $dir
NetAdapterWorker -NicName $name -OutDir $dir
if ($Type -eq "pNIC") {
NicVendor -NicName $name -OutDir $dir
} elseif ($Type -eq "hNIC") {
HostVNicWorker -DeviceID $nic.DeviceID -OutDir $dir
}
} # NetAdapterWorkerPrepare()
function LbfoWorker {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $LbfoName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$name = $LbfoName
$title = "LBFO.$name"
$Global:NetLbfoTracker += $LbfoName
$dir = Join-Path $OutDir $(ConvertTo-Filename $title)
New-Item -ItemType directory -Path $dir | Out-Null
Write-Progress -Activity $Global:QueueActivity -Status "Processing $title"
$file = "Get-NetLbfoTeam.txt"
[String []] $cmds = "Get-NetLbfoTeam -Name ""$name""",
"Get-NetLbfoTeam -Name ""$name"" | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetLbfoTeamNic.txt"
[String []] $cmds = "Get-NetLbfoTeamNic -Team ""$name""",
"Get-NetLbfoTeamNic -Team ""$name"" | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$file = "Get-NetLbfoTeamMember.txt"
[String []] $cmds = "Get-NetLbfoTeamMember -Team ""$name""",
"Get-NetLbfoTeamMember -Team ""$name"" | Format-List -Property *"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
# Report the TNIC(S)
foreach ($tnic in TryCmd {Get-NetLbfoTeamNic -Team $name}) {
NetAdapterWorkerPrepare -NicName $tnic.Name -Type "NIC" -OutDir $OutDir
}
# Report the NIC Members
foreach ($mnic in TryCmd {Get-NetLbfoTeamMember -Team $name}) {
NetAdapterWorkerPrepare -NicName $mnic.Name -Type "NIC" -OutDir $OutDir
}
} # LbfoWorker()
function LbfoDetail {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
$dir = $OutDir
# Query remaining LBFO teams (non-Protocol NICs).
$lbfoTeams = TryCmd {Get-NetLbfoTeam} | where {$_.Name -notin $script:NetLbfoTracker}
foreach ($lbfo in $lbfoTeams) {
LbfoWorker -LbfoName $lbfo.Name -OutDir $dir
}
} # LbfoDetail()
function ProtocolNicDetail {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $VMSwitchId,
[parameter(Mandatory=$true)] [String] $OutDir
)
$id = $VMSwitchId
$dir = $OutDir
$vmsNicDescriptions = TryCmd {(Get-VMSwitch -Id $id).NetAdapterInterfaceDescriptions}
foreach ($desc in $vmsNicDescriptions) {
$nic = Get-NetAdapter -InterfaceDescription $desc
if (-not $nic) {
$msg = "No NetAdapter found with desciption ""$desc""."
ExecControlError -OutDir $dir -Message $msg
continue
}
if ($nic.DriverFileName -like "NdisImPlatform.sys") {
LbfoWorker -LbfoName $nic.Name -OutDir $dir
} else {
NetAdapterWorkerPrepare -NicName $nic.Name -Type "pNIC" -OutDir $dir
}
}
} # ProtocolNicDetail()
function NativeNicDetail {
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] [String] $OutDir
)
$dir = $OutDir
# Query all remaining NetAdapters
$nics = Get-NetAdapter -IncludeHidden | where {$_.ifIndex -notin $script:NetAdapterTracker}
foreach ($nic in $nics) {
$type = if (Get-NetAdapterHardwareInfo -Name $nic.Name -IncludeHidden -ErrorAction "SilentlyContinue") {"pNIC"} else {"NIC"}
NetAdapterWorkerPrepare -NicName $nic.Name -Type $type -OutDir $dir
}
} # NativeNicDetail()
function NicDetail {
# Track which NICs or LBFO teams have been queried.
$script:NetAdapterTracker = @()
$script:NetLbfoTracker = @()
# These functions must be called in the correct order.
VMSwitchDetail -OutDir $workDir
LbfoDetail -OutDir $workDir
NativeNicDetail -OutDir $workDir
} # NicDetail()
function ChelsioDetailPerASIC {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$hwInfo = Get-NetAdapterHardwareInfo -Name "$NicName"
$locationInfo = $hwInfo.LocationInformationString
$dirBusName = "BusDev_$($hwInfo.BusNumber)_$($hwInfo.DeviceNumber)_$($hwInfo.FunctionNumber)"
$dir = Join-Path $OutDir $dirBusName
if ($Global:ChelsioDeviceDirs.ContainsKey($locationInfo)) {
New-LnkShortcut -LnkFile "$dir.lnk" -TargetPath $Global:ChelsioDeviceDirs[$locationInfo]
return # avoid duplicate work
} else {
$Global:ChelsioDeviceDirs[$locationInfo] = $dir
$null = New-Item -ItemType Directory -Path $dir
}
# Enumerate VBD
$ifNameVbd = ""
[Array] $PnPDevices = Get-PnpDevice -FriendlyName "*Chelsio*Enumerator*" | where {$_.Status -eq "OK"}
for ($i = 0; $i -lt $PnPDevices.Count; $i++) {
$instanceId = $PnPDevices[$i].InstanceId
$locationInfo = (Get-PnpDeviceProperty -InstanceId "$instanceId" -KeyName "DEVPKEY_Device_LocationInfo").Data
if ($hwInfo.LocationInformationString -eq $locationInfo) {
$ifNameVbd = "vbd$i"
break
}
}
if ([String]::IsNullOrEmpty($ifNameVbd)) {
$msg = "No bus device found for NIC ""$NicName""."
ExecControlError -OutDir $dir -Message $msg
return
}
$file = "ChelsioDetail-Firmware-BusDevice$i.txt"
[String []] $cmds = "cxgbtool.exe $ifNameVbd firmware mbox 1",
"cxgbtool.exe $ifNameVbd firmware mbox 2",
"cxgbtool.exe $ifNameVbd firmware mbox 3",
"cxgbtool.exe $ifNameVbd firmware mbox 4",
"cxgbtool.exe $ifNameVbd firmware mbox 5",
"cxgbtool.exe $ifNameVbd firmware mbox 6",
"cxgbtool.exe $ifNameVbd firmware mbox 7"
ExecCommands -OutDir $dir -File $file -Commands $cmds
$file = "ChelsioDetail-Hardware-BusDevice$i.txt"
[String []] $cmds = "cxgbtool.exe $ifNameVbd hardware sgedbg"
ExecCommands -OutDir $dir -File $file -Commands $cmds
$file = "ChelsioDetail-Dumps-BusDevice$i.txt"
[String []] $cmds = "cxgbtool.exe $ifNameVbd hardware flash ""$dir\Hardware-BusDevice$i-flash.dmp""",
"cxgbtool.exe $ifNameVbd cudbg collect all ""$dir\Cudbg-Collect.dmp""",
"cxgbtool.exe $ifNameVbd cudbg readflash ""$dir\Cudbg-Readflash.dmp"""
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
} # ChelsioDetailPerASIC()
function ChelsioDetail {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$dir = (Join-Path -Path $OutDir -ChildPath "ChelsioDetail")
New-Item -ItemType Directory -Path $dir | Out-Null
$file = "ChelsioDetail-Misc.txt"
[String []] $cmds = "verifier /query",
"Get-PnpDevice -FriendlyName ""*Chelsio*Enumerator*"" | Get-PnpDeviceProperty -KeyName DEVPKEY_Device_DriverVersion | Format-Table -Autosize"
ExecCommandsAsync -OutDir $dir -File $file -Commands $cmds
$cxgbtoolTest = TryCmd {cxgbtool.exe}
if (-not $cxgbtoolTest) {
$msg = "cxgbtool is required to collect Chelsio diagnostics."
ExecControlError -OutDir $dir -Message $msg
return
}
ChelsioDetailPerASIC -NicName $NicName -OutDir $dir
$ifIndex = (Get-NetAdapter $NicName).InterfaceIndex
$dirNetName = "NetDev_$ifIndex"
$dirNet = (Join-Path -Path $dir -ChildPath $dirNetName)
New-Item -ItemType Directory -Path $dirNet | Out-Null
# Enumerate NIC
$netDevices = Get-NetAdapter -InterfaceDescription "*Chelsio*" | where {$_.Status -eq "Up"} | sort -Property MacAddress
$nicIndex = @($netDevices.Name).IndexOf($NicName)
if ($nicIndex -eq -1) {
$msg = "Invalid state for NIC ""$NicName"". Make sure status is ""Up""."
ExecControlError -OutDir $dir -Message $msg
return
}
$file = "ChelsioDetail-Debug.txt"
[String []] $cmds = "cxgbtool.exe nic$nicIndex debug filter",
"cxgbtool.exe nic$nicIndex debug qsets",
"cxgbtool.exe nic$nicIndex debug qstats txeth rxeth txvirt rxvirt txrdma rxrdma txnvgre rxnvgre",
"cxgbtool.exe nic$nicIndex debug dumpctx",
"cxgbtool.exe nic$nicIndex debug version",
"cxgbtool.exe nic$nicIndex debug eps",
"cxgbtool.exe nic$nicIndex debug qps",
"cxgbtool.exe nic$nicIndex debug rdma_stats",
"cxgbtool.exe nic$nicIndex debug stags",
"cxgbtool.exe nic$nicIndex debug l2t"
ExecCommandsAsync -OutDir $dirNet -File $file -Commands $cmds
$file = "ChelsioDetail-Hardware.txt"
[String []] $cmds = "cxgbtool.exe nic$nicIndex hardware tid_info",
"cxgbtool.exe nic$nicIndex hardware fec",
"cxgbtool.exe nic$nicIndex hardware link_cfg",
"cxgbtool.exe nic$nicIndex hardware pktfilter",
"cxgbtool.exe nic$nicIndex hardware sensor"
ExecCommandsAsync -OutDir $dirNet -File $file -Commands $cmds
} # ChelsioDetail()
function MellanoxFirmwareInfo {
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] [String] $NicName,
[parameter(Mandatory=$true)] [String] $OutDir
)
$dir = $OutDir
$mstStatus = TryCmd {mst status -v}
if ((-not $mstStatus) -or ($mstStatus -like "*error*")) {
$msg = "Mellanox Firmware Tools (MFT) is required to collect firmware diagnostics."
ExecControlError -OutDir $dir -Message $msg
return
}
#
# Parse "mst status" output and match to Nic
#
[Bool] $found = $false
$hwInfo = Get-NetAdapterHardwareInfo -Name $NicName
foreach ($line in ($mstStatus | where {$_ -like "*pciconf*"})) {
$device, $info = $line.Trim() -split " "
$busNum, $deviceNum, $functionNum = $info -split "[:.=]" | select -Last 3 | foreach {[Int64]"0x$_"}
if (($hwInfo.Bus -eq $busNum) -and ($hwInfo.Device -eq $deviceNum) -and ($hwInfo.Function -eq $functionNum)) {
$found = $true
$device = $device.Trim()
break
}
}
if (-not $found) {
$msg = "No device found in mst status matching NIC ""$NicName""."