Central Management - Service - Error during installation when providing existing certificate: Cannot index into a null array #143
Labels
5 - Released
The area addressed in the ticket has been released in the product and is generally available.
Bug
Tickets that represent defects/bugs.
CentralManagement
Issues affecting Central Management
Edition - Business
Hi Everyone,
There is an error in the code which throws this Cannot index into a null array
the issues is produced when starting the installation while providing an existing certificate thumbprint
Here the thumbprint is checked and the value is assigned to the variable, the issue is with the else part, at this point the $existingCertificatesCoun is null since there was no values assigned to it, then a switch is called checking the value of this variable, in this case the switch fails since the value is null
I believe the Else should include the switch for the logic to function properly
If ($pp['CertificateThumbprint']) {
$certificateHash = $pp['CertificateThumbprint']
} Else {
$existingCertificates = (Get-ChildItem -Path Cert:\LocalMachine\TrustedPeople, Cert:\LocalMachine\My | Where-Object { $_.Subject -like "CN=$certificateDnsName*" } | Sort-Object -Property NotBefore | Select-Object *)
$existingCertificatesCount = ($existingCertificates | Measure-Object).Count
}
Switch ($existingCertificatesCount) {
0 {
Write-Output "Creating self signed certificate"
}
1 {
Write-Warning "A single self-signed Certificate matching Subject $certificateDnsName was found. Using this to continue installation"
$certificateHash = $existingCertificates[0].Thumbprint
}
default {
Write-Warning "Multiple self-signed Certificates were found matching Subject $certificateDnsName. Using the oldest Certificate to continue installation."
$certificateHash = $existingCertificates[0].Thumbprint
Write-Warning "Using $certificateHash"
}
}
Cheers,
Mohamed
References
The text was updated successfully, but these errors were encountered: