Execution Flow
dbatools is only used when
-CertificateName is supplied (to inspect an existing cert's endpoint binding and AG listeners for SAN generation). Without it, the function works as a pure offline CSR/INF generator and does not require dbatools. The actual certreq.exe -new call is the only state-changing action and is gated by ShouldProcess.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | SQL instance to inspect for an existing certificate/AG listeners (only used with -CertificateName). |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -CertificateName | String | Optional | Existing certificate to use as template for Subject/SANs. |
| -Database | String | Optional | Database to query for the certificate. Default: master. |
| -Subject | String | Optional | Certificate subject (CN=...). |
| -SubjectAlternativeNames | String[] | Optional | Additional SAN entries. |
| -KeyLength | Int | Optional | 2048 / 4096. Default: 4096. |
| -ValidityYears | Int | Optional | 1–10 years. Default: 3. |
| -Purpose | String | Optional | AlwaysOn / TDE / SSL / ServiceBroker / UserDefined. Default: SSL. |
| -OutputPath | String | Optional | Output directory. Default via Get-sqmDefaultOutputPath\Cert. |
| -Organization | String | Optional | O= field for the CSR subject. |
| -OrganizationalUnit | String | Optional | OU= field. |
| -Locality | String | Optional | L= field. |
| -State | String | Optional | S= field. |
| -Country | String | Optional | C= field. Default: DE. |
| -EnableException | Switch | Optional | Throws terminating errors instead of returning an error status object. |
| -WhatIf / -Confirm | Switch | Optional | Standard ShouldProcess support for the certreq.exe call. |
Return Value
Returns a PSCustomObject with: SqlInstance, ExistingCertName, Subject, SubjectAltNames, Purpose, KeyLength, ValidityYears, OutputDirectory, InfFile, CsrFile, CsrGenerated, OrderSheetFile, NextStep.
Examples
Example 1 — SSL certificate request
New-sqmCertificateRequest -Subject "CN=sql01.firma.de" -Purpose "SSL" -Organization "Firma GmbH"
Example 2 — Renewal based on existing AG certificate
New-sqmCertificateRequest -SqlInstance "SQL01" -CertificateName "AG_HADR_Cert" -Purpose "AlwaysOn"