Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/SdnDiagnostics.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,17 @@ function Start-SdnDataCollection {
[bool]$ConvertETW = $true
)

# if we are running in a remote session, we need to do some extra validation
if ($PSSenderInfo) {
# if we are running in a remote session and CredSSP is not enabled, then we need to ensure that
# the user has supplied -Credential to avoid double-hop authentication issues
if (-not (Get-WSManCredSSPState)) {
if ($Credential -ieq [System.Management.Automation.PSCredential]::Empty -or $null -ieq $Credential) {
throw New-Object System.NotSupportedException("Start-SdnDataCollection cannot be run in a remote session without supplying -Credential.")
}
}
}

$ErrorActionPreference = 'Continue'
$dataCollectionNodes = [System.Collections.ArrayList]::new() # need an arrayList so we can remove objects from this list

Expand Down
49 changes: 37 additions & 12 deletions src/modules/SdnDiag.Health.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,22 @@ function Debug-SdnFabricInfrastructure {
[X509Certificate]$NcRestCertificate
)

$script:SdnDiagnostics_Health.Cache = $null
$aggregateHealthReport = @()
# if we are running in a remote session, we need to do some extra validation
if ($PSSenderInfo) {
# if we are running in a remote session and CredSSP is not enabled, then we need to ensure that
# the user has supplied -Credential to avoid double-hop authentication issues
if (-not (Get-WSManCredSSPState)) {
if ($Credential -ieq [System.Management.Automation.PSCredential]::Empty -or $null -ieq $Credential) {
throw New-Object System.NotSupportedException("Debug-SdnFabricInfrastructure cannot be run in a remote session without supplying -Credential.")
}
}
}
if (Test-ComputerNameIsLocal -ComputerName $NetworkController) {
Confirm-IsNetworkController
}

$script:SdnDiagnostics_Health.Cache = $null
$aggregateHealthReport = @()
if ($PSBoundParameters.ContainsKey('NcRestCertificate')) {
$restCredParam = @{ NcRestCertificate = $NcRestCertificate }
}
Expand Down Expand Up @@ -504,6 +514,7 @@ function Debug-SdnFabricInfrastructure {
$report.HealthTest += @(
Test-SdnResourceProvisioningState @ncRestParamsResource
Test-SdnResourceConfigurationState @ncRestParamsResource
Test-ServerHostId -ComputerName $mgmtFqdnIpAddress -Credential $Credential -InstanceId $server.InstanceId
)
}
}
Expand Down Expand Up @@ -1057,26 +1068,40 @@ function Test-ServerHostId {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]$InstanceId
)
[string]$ComputerName,

Confirm-IsServer
[Parameter(Mandatory = $false)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty,

[Parameter(Mandatory = $true)]
[string]$InstanceId
)

$sdnHealthTest = New-SdnHealthTest
$regkeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\NcHostAgent\Parameters'

$scriptBlock = {
param ($path)
$regHostId = Get-ItemProperty -Path $path -Name 'HostId' -ErrorAction Ignore
return $regHostId
}

try {
$regHostId = Get-ItemProperty -Path $regkeyPath -Name 'HostId' -ErrorAction Ignore
if ($null -ieq $regHostId) {
$remoteHostID = Invoke-SdnCommand -ComputerName $ComputerName -Credential $Credential -ScriptBlock $scriptBlock -ArgumentList $regkeyPath
if ($null -ieq $remoteHostID) {
$sdnHealthTest.Result = 'FAIL'
}
else {
if ($regHostId.HostId -inotin $InstanceId) {
if ($remoteHostID.HostId -ine $InstanceId) {
$sdnHealthTest.Result = 'FAIL'
$sdnHealthTest.Remediation += "Update the HostId registry under $regkeyPath to match the correct InstanceId from the NC Servers API."
$sdnHealthTest.Properties = [PSCustomObject]@{
HostID = $regHostId
}
$sdnHealthTest.Remediation += "Update the HostId registry under $regkeyPath to match the InstanceId of the Server Resource"
}

$sdnHealthTest.Properties = [PSCustomObject]@{
CurrentHostID = $remoteHostID.HostID
ExpectedHostID = $InstanceId
}
}
}
Expand Down