Skip to content

Commit ca14220

Browse files
andreasjordanclaude
andcommitted
New-DbaComputerCertificate - Run certreq quietly, so that a refused request reports instead of showing a dialog
Without -q certreq shows a modal "Certificate Request Processor" dialog when a submission is refused or the CA cannot be reached, as soon as the session has a window station, and the command waits for someone to click it away. The cleanup of the request folder also passed its message to Stop-Function positionally, which threw instead of warning. (do New-DbaComputerCertificate) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent adbba7f commit ca14220

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎public/New-DbaComputerCertificate.ps1‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ function New-DbaComputerCertificate {
463463
$pendingRequestsBefore = @((Get-ChildItem -Path Cert:\LocalMachine\REQUEST -ErrorAction SilentlyContinue).Thumbprint)
464464

465465
if ($PScmdlet.ShouldProcess("local", "Creating certificate for $computer")) {
466-
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Running: certreq -new $certCfg $certCsr"
467-
$create = certreq -new $certCfg $certCsr
466+
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Running: certreq -q -new $certCfg $certCsr"
467+
$create = certreq -q -new $certCfg $certCsr
468468
}
469469

470470
if ($SelfSigned) {
@@ -488,13 +488,13 @@ function New-DbaComputerCertificate {
488488
}
489489
} else {
490490
if ($PScmdlet.ShouldProcess("local", "Submitting certificate request for $computer to $CaServer\$CaName")) {
491-
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "certreq -submit -config `"$CaServer\$CaName`" -attrib $certTemplate $certCsr $certCrt $certPfx"
492-
$submit = certreq -submit -config "$CaServer\$CaName" -attrib $certTemplate $certCsr $certCrt $certPfx
491+
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "certreq -q -submit -config `"$CaServer\$CaName`" -attrib $certTemplate $certCsr $certCrt $certPfx"
492+
$submit = certreq -q -submit -config "$CaServer\$CaName" -attrib $certTemplate $certCsr $certCrt $certPfx
493493
}
494494

495495
if ($submit -match "ssued") {
496-
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "certreq -accept -machine $certCrt"
497-
$null = certreq -accept -machine $certCrt
496+
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "certreq -q -accept -machine $certCrt"
497+
$null = certreq -q -accept -machine $certCrt
498498
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 ($certCrt, $null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
499499
$storedCert = Get-ChildItem "Cert:\$store\$folder" -Recurse | Where-Object { $_.Thumbprint -eq $cert.Thumbprint }
500500
} elseif ($submit) {
@@ -593,7 +593,7 @@ function New-DbaComputerCertificate {
593593
try {
594594
Remove-Item -Force -Recurse $certDir -ErrorAction SilentlyContinue
595595
} catch {
596-
Stop-Function "Isue removing files from $certDir" -Target $certDir -ErrorRecord $_
596+
Stop-Function -Message "Issue removing files from $certDir" -Target $certDir -ErrorRecord $PSItem
597597
}
598598
}
599599
Write-ProgressHelper -Completed

0 commit comments

Comments
 (0)