Skip to content

Commit 2252e9e

Browse files
Update script hooks info for SQL server and CSP conversion
1 parent 50c5f89 commit 2252e9e

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

docs/script-hooks.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ if ($result.IsSuccess -and $result.ManagedItem.GroupId -eq 1) {
148148

149149
```PowerShell
150150
param($result)
151-
$tempfile = "$env:TEMP\CertifyTemp.pfx"
152-
$pfx = get-pfxcertificate -filepath $result.ManagedItem.CertificatePath
153-
certutil -f -p Certify -exportpfx $pfx.SerialNumber $tempfile
154-
certutil -delstore my $pfx.SerialNumber
155-
certutil -p Certify -csp "Microsoft RSA SChannel Cryptographic Provider" -importpfx $tempfile
156-
remove-item $tempfile
151+
152+
# certutil import with blank password
153+
Write-Output "`n`n" | certutil -csp "Microsoft RSA SChannel Cryptographic Provider" -importPFX $result.ManagedItem.CertificatePath
154+
155+
# certutil import with a specific password
156+
#certutil -p <thepassword> -csp "Microsoft RSA SChannel Cryptographic Provider" -importPFX $result.ManagedItem.CertificatePath
157157
```
158158

159159
### Example: Enable certificate for Exchange 2013 / 2016 services on local server
@@ -208,28 +208,11 @@ This example updates the registry key for the SQL Server certificate thumbprint.
208208
```PowerShell
209209
param($result)
210210
211-
# Example script to set SQL Server certificate
212-
213-
# Note that some instances of SQL server may require certificate key storage to use the "Microsoft RSA SChannel Cryptographic Provider"
214-
# See an example conversion: https://docs.certifytheweb.com/docs/script-hooks#example-convert-cng-certificate-storage-to-csp-for-exchange-2013
215-
216-
# See HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\ for the required instance key
217-
$instanceKey = 'MSSQL15.MSSQLSERVER' # Change this as required
211+
$registryPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\*\MSSQLServer\SuperSocketNetLib"
218212
219-
# -------------------------------------------------------------------------
213+
# apply the new certificate thumbprint to the registry key
214+
Set-ItemProperty -Path $registryPath -Name 'Certificate' -Value $result.ManagedItem.CertificateThumbprintHash
220215
221-
$registryPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceKey\MSSQLServer\SuperSocketNetLib"
222-
$oldthumb = (Get-Itemproperty -Path $registryPath).Certificate
223-
$newthumb = $result.ManagedItem.CertificateThumbprintHash
224-
225-
if ($oldthumb -ne $newthumb) {
226-
227-
# apply the new certificate thumbprint to the registry key
228-
Set-ItemProperty -Path $registryPath -Name 'Certificate' -Value $newthumb
229-
230-
# optionally restart the SQL service (uncomment if required in this step), correct service name may vary
231-
# Restart-Service mssqlserver
232-
}
233216
```
234217

235218

0 commit comments

Comments
 (0)