New-SelfSignedCertificate

New-SelfSignedCertificate

Creates a new self-signed certificate for testing purposes.

Syntax

Parameter Set: Default
New-SelfSignedCertificate [-CertStoreLocation <String> ] [-CloneCert <Certificate> ] [-DnsName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The New-SelfSignedCertificate cmdlet creates a self-signed certificate for testing purposes. Using the CloneCert parameter, a test certificate can be created based on an existing certificate with all settings copied from the original certificate except for the public key. A new key of the same algorithm and length will be created.

If an existing certificate is not being cloned, then an SSL server certificate with the following default settings is created:
-- Subject: Empty
-- Key: RSA 2048
-- EKUs: Client Authentication and Server Authentication
-- Key Usage: Digital Signature, Key Encipherment (a0)
-- Validity Period: One year

Delegation may be required when using this cmdlet with Windows PowerShell® remoting and changing user configuration.

Parameters

-CertStoreLocation<String>

Specifies the certificate store in which a new certificate will be stored. The current path is the default value.

Aliases

none

Required?

false

Position?

named

Default Value

.

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CloneCert<Certificate>

Identifies the certificate to copy when creating a new certificate. The certificate being cloned can be identified by an X509 certificate or the file path in the certificate provider. When this parameter is used, all fields and extensions of the certificate will be inherited except the public key (a new key of the same algorithm and length will be created) and the NotAfter and NotBefore fields (the validity period for the NotBefore field is set to ten minutes in the past).

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-DnsName<String>

Specifies one or more DNS names to put into the Subject Alternative Name extension of the certificate when a certificate to be copied is not specified via the CloneCert parameter. The first DNS name is also saved as Subject Name and Issuer Name.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • Microsoft.CertificateServices.Commands.Certificate

    The Certificate object can either be provided as a Path object to a certificate or a X509Certificate2 object.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.Security.Cryptography.X509Certificates.X509Certificate2

    A X509Certificate2 object for the certificate that has been created.

Examples

EXAMPLE 1

This example creates a self-signed SSL server certificate in the computer MY store with the Subject Alternative Name set to www.fabrikam.com, www.contoso.com and Subject and Issuer name set to www.fabrikam.com.

PS C:\> New-SelfSignedCertificate -DnsName www.fabrikam.com, www.contoso.com -CertStoreLocation cert:\LocalMachine\My

EXAMPLE 2

This example creates a copy of the certificate specified by the CloneCert parameter and puts it in the computer MY store.

PS C:\> Set-Location -Path cert:\LocalMachine\My
PS C:\> $copyOf = (Get-ChildItem -Path E42DBC3B3F2771990A9B3E35D0C3C422779DACD7)
PS C:\> New-SelfSignedCertificate -CloneCert $copyOf

Get-ChildItem

Set-Location