Execution Flow
Synopsis
Reads the certificate file once locally to get metadata (thumbprint, subject, expiry). For remote targets, the raw certificate bytes are passed as an argument to Invoke-Command — no file share access is required on the target. The import script block runs identically whether local or remote. Thumbprint deduplication prevents double-install silently.
No dbatools required. SupportsShouldProcess with ConfirmImpact=Medium. Requires Administrator rights and WinRM access for remote targets. PFX password is converted to plain text in memory only for the duration of the
Invoke-Command call and zeroed immediately after in the end block.Syntax
Install-sqmCertificateToStore -CertFile <String> # required; .cer/.crt/.pfx/.p12 [-StoreName <Root|My|TrustedPeople|CA>] # default Root [-ComputerName <String[]>] # default localhost [-CertPassword <SecureString>] # for PFX files
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -CertFile | String | — | Required. Path to the certificate file. Must exist and be readable. |
| -StoreName | String | Root | Target LocalMachine store: Root (Trusted Root CA), My (Personal), TrustedPeople, or CA (Intermediate CA). |
| -ComputerName | String[] | localhost | One or more target computers. Local when localhost, ., or matching $env:COMPUTERNAME. |
| -CertPassword | SecureString | — | Password for PFX files. Ignored for CER/CRT. |
Return Value (per target)
| Property | Description |
|---|---|
| ComputerName | Target computer name. |
| StoreName | Store where the certificate was installed. |
| Thumbprint | Certificate thumbprint. |
| Subject | Certificate subject (CN). |
| Expiry | Certificate expiry date (NotAfter). |
| Action | Installed — newly added; AlreadyPresent — thumbprint duplicate skipped; Failed — error occurred; Skipped — ShouldProcess declined. |
| ErrorMessage | Error text when Action = Failed. |
Examples
# Distribute CA root certificate to all AlwaysOn replica nodes $nodes = 'SQL-AG-01', 'SQL-AG-02', 'SQL-AG-03' Install-sqmCertificateToStore -CertFile 'C:\Certs\CompanyRootCA.cer' ` -StoreName Root -ComputerName $nodes # Distribute AlwaysOn partner certificate (CER) to My store on replicas Install-sqmCertificateToStore -CertFile 'C:\Certs\SQL-AG-01_AG_CERT.cer' ` -StoreName My -ComputerName 'SQL-AG-02','SQL-AG-03' # Install PFX with password into Personal store on local machine $pwd = Read-Host -AsSecureString 'PFX password' Install-sqmCertificateToStore -CertFile 'C:\Certs\sql-ssl.pfx' ` -StoreName My -CertPassword $pwd