commands

^

New-DbaComputerCertificate

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows only

 

Synopsis

Creates a new computer certificate useful for Forcing Encryption

Description

Creates a new computer certificate - self-signed or signed by an Active Directory CA, using the Web Server certificate.

By default, a key with a length of 1024 and a friendly name of the machines FQDN is generated.

This command was originally intended to help automate the process so that SSL certificates can be available for enforcing encryption on connections.

It makes a lot of assumptions - namely, that your account is allowed to auto-enroll and that you have permission to do everything it needs to do ;)

References: https://www.itprotoday.com/sql-server/7-steps-ssl-encryption https://azurebi.jppp.org/2016/01/23/using-lets-encrypt-certificates-for-secure-sql-server-connections/ https://blogs.msdn.microsoft.com/sqlserverfaq/2016/09/26/creating-and-registering-ssl-certificates/

The certificate is generated using AD's webserver SSL template on the client machine and pushed to the remote machine.

Syntax

New-DbaComputerCertificate
    [[-ComputerName] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-CaServer] <String>]
    [[-CaName] <String>]
    [[-ClusterInstanceName] <String>]
    [[-SecurePassword] <SecureString>]
    [[-FriendlyName] <String>]
    [[-CertificateTemplate] <String>]
    [[-KeyLength] <Int32>]
    [[-Store] <String>]
    [[-Folder] <String>]
    [[-Dns] <String[]>]
    [-SelfSigned]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> New-DbaComputerCertificate

Creates a computer certificate signed by the local domain CA for the local machine with the keylength of 1024.

Example: 2
PS C:\> New-DbaComputerCertificate -ComputerName Server1

Creates a computer certificate signed by the local domain CA on the local machine for server1 with the keylength of 1024.
The certificate is then copied to the new machine over WinRM and imported.

Example: 3
PS C:\> New-DbaComputerCertificate -ComputerName sqla, sqlb -ClusterInstanceName sqlcluster -KeyLength 4096

Creates a computer certificate for sqlcluster, signed by the local domain CA, with the keylength of 4096.
The certificate is then copied to sqla and sqlb over WinRM and imported.

Example: 4
PS C:\> New-DbaComputerCertificate -ComputerName Server1 -WhatIf

Shows what would happen if the command were run

Example: 5
PS C:\> New-DbaComputerCertificate -SelfSigned

Creates a self-signed certificate

Optional Parameters

-ComputerName

The target SQL Server instance or instances. Defaults to localhost. If target is a cluster, you must also specify ClusterInstanceName (see below)

Alias
Required False
Pipeline true (ByValue)
Default Value $env:COMPUTERNAME
-Credential

Allows you to login to $ComputerName using alternative credentials.

Alias
Required False
Pipeline false
Default Value
-CaServer

Optional - the CA Server where the request will be sent to

Alias
Required False
Pipeline false
Default Value
-CaName

The properly formatted CA name of the corresponding CaServer

Alias
Required False
Pipeline false
Default Value
-ClusterInstanceName

When creating certs for a cluster, use this parameter to create the certificate for the cluster node name. Use ComputerName for each of the nodes.

Alias
Required False
Pipeline false
Default Value
-SecurePassword

Password to encrypt/decrypt private key for export to remote machine

Alias Password
Required False
Pipeline false
Default Value
-FriendlyName

The FriendlyName listed in the certificate. This defaults to the FQDN of the $ComputerName

Alias
Required False
Pipeline false
Default Value SQL Server
-CertificateTemplate

The domain's Certificate Template - WebServer by default.

Alias
Required False
Pipeline false
Default Value WebServer
-KeyLength

The length of the key - defaults to 1024

Alias
Required False
Pipeline false
Default Value 1024
-Store

Certificate store - defaults to LocalMachine

Alias
Required False
Pipeline false
Default Value LocalMachine
-Folder

Certificate folder - defaults to My (Personal)

Alias
Required False
Pipeline false
Default Value My
-Dns

Specify the Dns entries listed in SAN. By default, it will be ComputerName + FQDN, or in the case of clusters, clustername + cluster FQDN.

Alias
Required False
Pipeline false
Default Value
-SelfSigned

Creates a self-signed certificate. All other parameters can still apply except CaServer and CaName because the command does not go and get the certificate signed.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value

 

Want to see the source code for this command? Check out New-DbaComputerCertificate on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaComputerCertificate.