Skip to content

Commit

Permalink
New-DbaComputerCertificate - Fix immutability issue (dataplat#8897)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored May 4, 2023
1 parent 83a5b99 commit 06d7aba
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions public/New-DbaComputerCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ function New-DbaComputerCertificate {
if ($submit -match "ssued") {
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "certreq -accept -machine $certCrt"
$null = certreq -accept -machine $certCrt
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($certCrt, $null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 ($certCrt, $null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
$storedCert = Get-ChildItem "Cert:\$store\$folder" -Recurse | Where-Object { $_.Thumbprint -eq $cert.Thumbprint }
} elseif ($submit) {
Write-Message -Level Warning -Message "Something went wrong"
Expand Down Expand Up @@ -413,8 +412,7 @@ function New-DbaComputerCertificate {
)
Write-Verbose -Message "Importing cert to $Folder\$Store using flags: $flags"

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($CertificateData, $SecurePassword, $flags)
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertificateData, $SecurePassword, $flags)
$certstore = New-Object System.Security.Cryptography.X509Certificates.X509Store($Folder, $Store)
$certstore.Open('ReadWrite')
$certstore.Add($cert)
Expand Down

0 comments on commit 06d7aba

Please sign in to comment.