Creates a new self-signed certificate for testing purposes.
Networking / Security · Risk: High · Documentation Verified
Last verified: 2026-10-26
Microsoft pki reference: Creates a new self-signed certificate for testing purposes. The syntax and selected example below are adapted from the pinned Windows Server 2025 reference. Module availability, target configuration and delegated permissions determine whether it can run in your environment. Documentation and parameter text: Microsoft, CC BY 4.0; formatting adapted by Cmdlet World. No execution testing is claimed.
Use an account with the target resource permissions documented for New-SelfSignedCertificate. Modifying administrative cmdlets may require elevation or delegated administration. This catalog does not assert that ordinary users can execute the command.
Supported environments
Windows / pki · Windows Server 2025 documentation; feature/module prerequisites apply
Parameters
-AlternateSignatureAlgorithm
Indicates that this cmdlet uses RSA-PSS (PKCSv2.1) or an elliptic curve cryptography (ECC) equivalent. If you do not specify this parameter, the cmdlet uses the default, RSA-PSS (PKCSv1.5) or an ECC equivalent.
-CertStoreLocation
Specifies the certificate store in which to store the new certificate. If the current path is Cert:\CurrentUser or Cert:\CurrentUser\My, the default store is Cert:\CurrentUser\My. If the current path is Cert:\LocalMachine or Cert:\LocalMachine\My, the default store is Cert:\LocalMachine\My. Otherwise, you must specify Cert:\CurrentUser\My or Cert:\LocalMachine\My for this parameter. This parameter does not support other certificate stores.
-CloneCert
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 NotAfter and NotBefore fields and the public key. A new key of the same algorithm and length will be created. The default validity period will be the same as the certificate to copy, except that the NotBefore field will be set to ten minutes in the past.
-Confirm
Prompts you for confirmation before running the cmdlet.
-Container
Specifies the name of the container in which this cmdlet stores the key for the new certificate. When you create a key, a trailing asterisk (*) indicates that the rest of the container name string is a prefix. An appended GUID string makes the container name unique. When you use an existing key, the container name must identify an existing key. You may also have to specify the provider.
-CurveExport
Specifies how the public key parameters for an elliptic curve key are represented in the new certificate. The acceptable values for this parameter are: - CurveParameters - CurveName - None The default value, None, indicates that this cmdlet uses the default value from the underlying key storage provider (KSP). This parameter is not supported with the RSA algorithm or with cryptographic service providers (CSPs).
-DnsName
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 the Subject Name. If no signing certificate is specified, the first DNS name is also saved as the Issuer Name.
-ExistingKey
Indicates that this cmdlet uses an existing key. If you do not specify this parameter, this cmdlet creates a new key. Creating a certificate from an existing key creates a new key with a new container. When you use an existing key, specify values for the Container parameter, the Provider parameter, and the CertStoreLocation parameter. CertStoreLocation determines the context. The context is user or computer.
Prerequisites
Windows with the pki module and the Windows feature or management tools that provide it. Confirm target connectivity and version compatibility using the linked Microsoft reference.
Security considerations
This cmdlet changes system state. Review every target and parameter in the official reference, test outside production, and prepare an appropriate backup or rollback. Do not execute the example automatically.
Examples
EXAMPLE 1
New-SelfSignedCertificate @params
This example creates a self-signed SSL server certificate in the computer MY store with the subject alternative names www.fabrikam.com and www.contoso.com and the Subject and Issuer name set to www.fabrikam.com. Source: Microsoft, CC BY 4.0; transcript prompt/output removed. This example was not executed.
Specifies an array of certificate extensions, as X509Extension objects, that this cmdlet includes in the new certificate.
-FriendlyName
Specifies a friendly name for the new certificate.
-HardwareKeyUsage
Specifies how a hardware key associated with the new certificate may be used. This parameter applies only when you specify the Microsoft Platform Crypto Provider. The acceptable values for this parameter are: - None - SignatureKey - EncryptionKey - GenericKey - StorageKey - IdentityKey The default value, None, indicates that this cmdlet uses the default value from the underlying KSP.
-HashAlgorithm
Specifies the name of the hash algorithm to use to sign the new certificate. The default hash algorithm depends on the provider that stores the private key used to sign the new certificate.
-KeyAlgorithm
Specifies the name of the algorithm that creates the asymmetric keys that are associated with the new certificate. Available asymmetric key algorithms are RSA and Elliptic Curve Digital Signature Algorithms (ECDSA). The elliptic curve algorithm syntax is the following: ECDSA_{curvename} To obtain a value for {curvename}, use the certutil -displayEccCurve command. Valid curve names contain a value in the Curve OID column in the output of the certutil -displayEccCurve command.
-KeyDescription
Specifies a description for the private key that is associated with the new certificate.
-KeyExportPolicy
Specifies the policy that governs the export of the private key that is associated with the certificate. The default value of ExportableEncrypted is not compatible with KSP and CSPs that do not allow key export. These include the Microsoft Smart Card Key Storage Provider and the Microsoft Platform Crypto Key Storage Provider. Specify NonExportable for providers that do not allow key export.
-KeyFriendlyName
Specifies a friendly name for the private key that is associated with the new certificate.
-KeyLength
Specifies the length, in bits, of the key that is associated with the new certificate.
-KeyLocation
Specifies the file system location where this cmdlet stores the private keys associated with the new certificate. Specify this parameter only when you specify the Microsoft Platform Crypto Provider.
-KeyProtection
Specifies the level of protection required to access the private key that is associated with the certificate. The acceptable values for this parameter are: - Protect - ProtectHigh - ProtectFingerPrint - None The default value, None, indicates that this cmdlet uses the default value from the underlying KSP or CSP. For most KSPs and CSPs, the default means that no user interface is required to create and use the private key. A user interface is required if the provider always requires a user interface, such as a smart card, or if the default configuration of the provider has been changed.
-KeySpec
Specifies whether the private key associated with the new certificate can be used for signing, encryption, or both. The acceptable values for this parameter are: - KeyExchange - Signature - None The default value, None, indicates that this cmdlet uses the default value from the underlying CSP. If the private key is managed by a legacy CSP, the value is KeyExchange or Signature. If the key is managed by a Cryptography Next Generation (CNG) KSP, the value is None.
-KeyUsage
Specifies the key usages set in the key usage extension of the certificate. The acceptable values for this parameter are: - CertSign - CRLSign - DataEncipherment - DecipherOnly - DigitalSignature - EncipherOnly - KeyAgreement - KeyEncipherment - None - NonRepudiation The value, None, indicates that this cmdlet does not include the KeyUsage extension in the new certificate.
-KeyUsageProperty
Specifies the key usages for the key usages property of the private key. The acceptable values for this parameter are: - All - Decrypt - KeyAgreement - None - Sign The default value, None, indicates that this cmdlet uses the default value from the underlying KSP.
-NotAfter
Specifies the date and time, as a DateTime object, that the certificate expires. To obtain a DateTime object, use the Get-Date cmdlet. The default value for this parameter is one year after the certificate was created.
-NotBefore
Specifies the date and time, as a DateTime object, when the certificate becomes valid. The default value for this parameter is 10 minutes before the certificate was created.
-Pin
Specifies the personal identification number (PIN) used to access the private key of the new certificate.
-Provider
Specifies the name of the KSP or CSP that this cmdlet uses to create the certificate. See Cryptographic Providers for more information. Some acceptable values include: - Microsoft Software Key Storage Provider - Microsoft Smart Card Key Storage Provider - Microsoft Platform Crypto Provider - Microsoft Strong Cryptographic Provider - Microsoft Enhanced Cryptographic Provider v1.0 - Microsoft Enhanced RSA and AES Cryptographic Provider - Microsoft Base Cryptographic Provider v1.0 - The name of a third party KSP or CSP
-Reader
Specifies the name of the smart card reader on which to store the private key for the new certificate.
-SecurityDescriptor
Specifies the private key security descriptor as a FileSecurity object. Read access is required to use the private key. This parameter does not apply to providers that do not support security descriptors on private keys, including the smart card CSP and smart card KSP.
-SerialNumber
Specifies a serial number, as a hexadecimal string, that is associated with the new certificate. If you do not specify this parameter, this cmdlet assigns a pseudo-randomly generated 16-byte value.
-Signer
Specifies a Certificate object with which this cmdlet signs the new certificate. This value must be in the Personal certificate store of the user or device. This cmdlet must have read access to the private key of the certificate.
-SignerPin
Specifies the PIN that is required to access the private key of the certificate that is used to sign the new certificate.
-SignerReader
Specifies the name of the smart card reader that is used to sign the new certificate.
-SmimeCapabilities
Indicates that the new certificate includes available encryption algorithms to a Secure/Multipurpose Internet Mail Extensions (S/MIME) capabilities extension.
-Subject
Specifies the string that appears in the subject of the new certificate. This cmdlet prefixes CN= to any value that does not contain an equal sign. For multiple subject relative distinguished names (also known as RDNs), separate each subject relative distinguished name with a comma (,). If the value of the relative distinguished name contains commas, separate each subject relative distinguished name with a semicolon (;).
-SuppressOid
Specifies an array of object identifier (also known as OID) strings that identify default extensions to be removed from the new certificate.
-TestRoot
Indicates that this cmdlet signs the new certificate by using a built-in test certificate. This cmdlet adds the built-in test certificate to the intermediate certification authority (CA) certificate store of the device. This parameter is for test purposes only. The private key of the test root certificate is essentially public.
-TextExtension
Specifies an array of certificate extensions, as strings, which this cmdlet includes in the new certificate. Each string must employ one of the following formats: {oid}={base64String}, where {oid} is the object identifier of the extension and {base64String} is a value that you provide. After decoding {base64String}, the value must be valid Abstract Syntax Notation One (ASN.1). For more information, see Abstract Syntax Notation One (ASN.1): Specification of basic notation. {oid}={hex}{hexadecimalString}, where {oid} is the object identifier of the extension and {hexadecimalString} is a value that you provide. After decoding {hexadecimalString}, the value must be valid ASN.1. {oid}={text}{String}, where {oid} is the object identifier of the extension and {String} is a value that you provide. {String} must contain a textual representation of the extension value in a format specific to each object ID. When {String} is processed, it will be encoded into an ASN.1 extension value before being placed into the new certificate as an extension. To specify that an extension is critical, insert {critical} immediately following {oid}= in any of the previous cases. The object identifiers of some common extensions are as follows: - Application Policy: 1.3.6.1.4.1.311.21.10 - Application Policy Mappings: 1.3.6.1.4.1.311.21.11 - Basic Constraints: 2.5.29.19 - Certificate Policies: 2.5.29.32 - Enhanced Key Usage: 2.5.29.37 - Name Constraints: 2.5.29.30 - Policy Mappings: 2.5.29.33 - Subject Alternative Name: 2.5.29.17 Application Policy extension example: 1.3.6.1.4.1.311.21.10={text}{token}={value}&{token}={value}... You can specify the following tokens in an Application Policy extension: - Flags: Bitwise flags in hexadecimal notation: 0x{hexadecimalNumber} - GUID: A globally unique ID, such as this example: f7c3ac41-b8ce-4fb4-aa58-3d1dc0e36b39 - Notice: Text notice - OID: Object identi
-Type
Specifies the type of certificate that this cmdlet creates.
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.