Closed 2Deep2Dive closed 4 years ago
I had this some problem, I can confirm that putting the switch statement within the ELSE block as suggested will fix it.
Howdy folks, just moved this over to https://github.com/chocolatey/chocolatey-licensed-issues/issues/143 as it is not a problem with the wiki. Updated the issue name as well. Thanks for finding this.
This has been fixed for Chocolatey Central Management v0.2.0. Thanks for letting us know about the issue!
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