Skip to content

Commit 9a66e82

Browse files
authored
Code fixes - 2026.01 (#537)
This pull request introduces improvements to remote session handling, logging, and output formatting in the SDN diagnostics and health validation scripts. The main changes include enforcing credential requirements for remote sessions, adding transcript logging, and standardizing output visuals. **Remote session validation and credential handling:** - Added checks in both `Start-SdnDataCollection` and `Debug-SdnFabricInfrastructure` to ensure that when running in a remote session without CredSSP enabled, the user must supply the `-Credential` parameter to avoid double-hop authentication issues. If not, the functions throw a `NotSupportedException`. [[1]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eR757-R767) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R403-R416) - Set a default value for the `$Credential` parameter in `Show-SdnGatewayUtilization` to prevent null credential issues. **Logging and transcript improvements:** - Introduced transcript logging at the start of data collection and health validation processes, and ensured transcripts are stopped appropriately to capture command output for troubleshooting. [[1]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eR835) [[2]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eR1160) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L411-L415) **Output and formatting enhancements:** - Updated bar chart characters in `Show-SdnGatewayUtilization` from Unicode blocks (`█`, `░`) to ASCII characters (`=`, `.`) for improved compatibility and readability. [[1]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eL1464-R1477) [[2]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eL1482-R1495) [[3]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eL1493-R1506) - Improved remediation message formatting in `Test-SdnCertificateMultiple` by adding indentation for better clarity. **Minor logic adjustments:** - Moved the network controller confirmation check in `Debug-SdnFabricInfrastructure` to occur only after remote session validation, ensuring proper sequencing. [[1]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R403-R416) [[2]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L411-L415) [[3]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60R433) # Change type - [x] Bug fix (non-breaking change) - [ ] Code style update (formatting, local variables) - [ ] New Feature (non-breaking change that adds new functionality without impacting existing) - [ ] Breaking change (fix or feature that may cause functionality impact) - [ ] Other # Checklist: - [x] My code follows the style and contribution guidelines of this project. - [x] I have tested and validated my code changes.
1 parent 0485fe1 commit 9a66e82

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/SdnDiagnostics.psm1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,17 @@ function Start-SdnDataCollection {
754754
[bool]$ConvertETW = $true
755755
)
756756

757+
# if we are running in a remote session, we need to do some extra validation
758+
if ($PSSenderInfo) {
759+
# if we are running in a remote session and CredSSP is not enabled, then we need to ensure that
760+
# the user has supplied -Credential to avoid double-hop authentication issues
761+
if (-not (Get-WSManCredSSPState)) {
762+
if ($Credential -ieq [System.Management.Automation.PSCredential]::Empty -or $null -ieq $Credential) {
763+
throw New-Object System.NotSupportedException("Start-SdnDataCollection cannot be run in a remote session without supplying -Credential.")
764+
}
765+
}
766+
}
767+
757768
$ErrorActionPreference = 'Continue'
758769
$dataCollectionNodes = [System.Collections.ArrayList]::new() # need an arrayList so we can remove objects from this list
759770

@@ -821,7 +832,8 @@ function Start-SdnDataCollection {
821832
[System.IO.FileInfo]$OutputDirectory = Join-Path -Path $OutputDirectory.FullName -ChildPath $childPath
822833
[System.IO.FileInfo]$workingDirectory = (Get-WorkingDirectory)
823834
[System.IO.FileInfo]$tempDirectory = "$(Get-WorkingDirectory)\Temp"
824-
835+
$null = Start-Transcript -Path (Join-Path -Path $OutputDirectory.FullName -ChildPath 'DataCollection_Transcript.txt') -ErrorAction Stop
836+
825837
# setup the directory location where files will be saved to
826838
"Starting SDN Data Collection" | Trace-Output
827839

@@ -1145,6 +1157,7 @@ function Start-SdnDataCollection {
11451157
}
11461158
}
11471159

1160+
$null = Stop-Transcript -ErrorAction Ignore
11481161
return $dataCollectionObject
11491162
}
11501163

@@ -1255,7 +1268,7 @@ function Show-SdnGatewayUtilization {
12551268
[Parameter(Mandatory = $false)]
12561269
[System.Management.Automation.PSCredential]
12571270
[System.Management.Automation.Credential()]
1258-
$Credential
1271+
$Credential = [System.Management.Automation.PSCredential]::Empty
12591272
)
12601273

12611274
$ncRestParams = @{
@@ -1461,7 +1474,7 @@ function Show-SdnGatewayUtilization {
14611474
$barLength = 40
14621475
$filledLength = [int][Math]::Round(($utilizationPercent / 100) * $barLength)
14631476
$emptyLength = $barLength - $filledLength
1464-
$bar = ("" * $filledLength) + ("" * $emptyLength)
1477+
$bar = ("=" * $filledLength) + ("." * $emptyLength)
14651478

14661479
# Determine color based on utilization thresholds
14671480
$barColor = if ($utilizationPercent -ge 90) { 'Red' }
@@ -1479,7 +1492,7 @@ function Show-SdnGatewayUtilization {
14791492
"`t`tCPU Utilization (sampled at {0}):" -f $gateway.CpuMetrics.Timestamp.ToString('yyyy-MM-dd HH:mm:ss') | Write-Host -ForegroundColor Cyan
14801493

14811494
foreach ($cpu in $gateway.CpuMetrics.Processors | Sort-Object -Property ProcessorId) {
1482-
$cpuBar = '' * [int]($cpu.Utilization / 2.5) # Scale to ~40 chars max
1495+
$cpuBar = '=' * [int]($cpu.Utilization / 2.5) # Scale to ~40 chars max
14831496
$cpuColor = if ($cpu.Utilization -ge 90) { 'Red' }
14841497
elseif ($cpu.Utilization -ge 75) { 'Yellow' }
14851498
else { 'Green' }
@@ -1490,7 +1503,7 @@ function Show-SdnGatewayUtilization {
14901503
}
14911504

14921505
# Display average
1493-
$avgBar = '' * [int]($gateway.CpuMetrics.AverageUtilization / 2.5)
1506+
$avgBar = '=' * [int]($gateway.CpuMetrics.AverageUtilization / 2.5)
14941507
$avgColor = if ($gateway.CpuMetrics.AverageUtilization -ge 90) { 'Red' }
14951508
elseif ($gateway.CpuMetrics.AverageUtilization -ge 75) { 'Yellow' }
14961509
else { 'Green' }

src/modules/SdnDiag.Health.psm1

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,20 @@ function Debug-SdnFabricInfrastructure {
400400
[switch]$SkipSummaryDisplay
401401
)
402402

403+
# if we are running in a remote session, we need to do some extra validation
404+
if ($PSSenderInfo) {
405+
# if we are running in a remote session and CredSSP is not enabled, then we need to ensure that
406+
# the user has supplied -Credential to avoid double-hop authentication issues
407+
if (-not (Get-WSManCredSSPState)) {
408+
if ($Credential -ieq [System.Management.Automation.PSCredential]::Empty -or $null -ieq $Credential) {
409+
throw New-Object System.NotSupportedException("Debug-SdnFabricInfrastructure cannot be run in a remote session without supplying -Credential.")
410+
}
411+
}
412+
}
413+
if (Test-ComputerNameIsLocal -ComputerName $NetworkController) {
414+
Confirm-IsNetworkController
415+
}
416+
403417
$script:SdnDiagnostics_Health.Cache = $null
404418
$aggregateHealthReport = @()
405419
$dateTimeNow = Get-Date -Format 'yyyyMMdd-HHmmss'
@@ -408,11 +422,6 @@ function Debug-SdnFabricInfrastructure {
408422
$transcriptDirectory = Get-WorkingDirectory
409423
$transcriptPath = "{0}\SdnFabricHealthReport_{1}.txt" -f $transcriptDirectory, $dateTimeNow
410424
$null = Start-Transcript -Path $transcriptPath -Force
411-
"Starting SDN Fabric Infrastructure health validation at {0}" -f $dateTimeNowFormatted | Trace-Output -Level:Information
412-
413-
if (Test-ComputerNameIsLocal -ComputerName $NetworkController) {
414-
Confirm-IsNetworkController
415-
}
416425

417426
if ($PSBoundParameters.ContainsKey('NcRestCertificate')) {
418427
$restCredParam = @{ NcRestCertificate = $NcRestCertificate }
@@ -421,6 +430,7 @@ function Debug-SdnFabricInfrastructure {
421430
$restCredParam = @{ NcRestCredential = $NcRestCredential }
422431
}
423432

433+
"Starting SDN Fabric Infrastructure health validation at {0}" -f $dateTimeNowFormatted | Trace-Output -Level:Information
424434
$environmentInfo = Get-SdnInfrastructureInfo -NetworkController $NetworkController -Credential $Credential @restCredParam
425435
if ($null -eq $environmentInfo) {
426436
throw New-Object System.NullReferenceException("Unable to retrieve environment details")
@@ -1170,7 +1180,7 @@ function Test-SdnCertificateMultiple {
11701180
}
11711181

11721182
$sdnHealthTest.Result = 'WARNING'
1173-
$sdnHealthTest.Remediation = "Examine and cleanup the certificates if no longer needed:`r`n{0}" -f ($certDetails -join "`r`n")
1183+
$sdnHealthTest.Remediation = "Examine and cleanup the certificates if no longer needed:`r`n`t{0}" -f ($certDetails -join "`r`n`t")
11741184
}
11751185
}
11761186
catch {

0 commit comments

Comments
 (0)