Powershell

How to Manage Certificates(Certs) with Windows PowerShell?

In PowerShell, Windows certificate manager enables the users to (manage) add, clear, alter, and delete certificate stores. It provides access to X.509 certificates and certificate stores. Windows has a drive by the name of “cert:”. It is a hierarchical namespace that consists of certificates and certificate stores available on the local system.

In this tutorial, the management of the certificates will be illustrated.

How to Manage Certificates(Certs) with Windows PowerShell?

PowerShell is an administrative tool that lets the user manage all the administration tasks including the management of certificates also.

Let’s see how PowerShell triumphs in managing the certificates.

Example 1: List Down the Available Certificates on the Computer

In order to get the available certificates, specify the “Get-ChildItem” cmdlet along with the “-Path” parameter having the stated path assigned to it:

Get-ChildItem -Path Cert:\CurrentUser\My

Example 2: Create a Certificate With Six Months of Expiry

Execute the provided command to create a certificate with six months of expiry:

New-SelfSignedCertificate -Subject Longer_Expiry -CertStoreLocation Cert:\CurrentUser\My -NotAfter (Get-Date).AddMonths(06)

According to the above-stated code:

  • Specify the “New-SelfSignedCertificate” cmdlet and the “-Subject” parameter then assign it a subject name.
  • Next, mention the “-CertStoreLocation” parameter and provide it with the location of the certificates.
  • Lastly, add the “-NotAfter” parameter having the certificate expiry date assigned to it:

Example 3: Create a Self-Signed Certificate in PowerShell

To create a self-signed certificate, execute the provided command:

$Test_Cert = New-SelfSignedCertificate -Type DocumentEncryptionCert -Subject "Encrypt_Doc" -CertStoreLocation Cert:\CurrentUser\My

$Test_Cert

In the above-mentioned code:

  • First, initialize a variable and assign it the stated code.
  • In the assigned code, first, add the “New-SelfSignedCertificate” cmdlet along with the parameter “-Type” having the “DocumentEncryptionCert” value specified to it.
  • Next, mention the subject and target location.
  • Lastly, invoke the variable to see the created certificate:

Example 4: Get the Details of a Certificate

Execute the given code to retrieve the detailed information of a certificate:

$New_Cert = Get-ChildItem -Path Cert:\CurrentUser\My\59722429099E950F29845B876F7585F46BE8F2D9

$New_Cert | fl

In the stated code above:

  • First, initialize a variable and assign it the “Get-ChildItem” cmdlet.
  • Next, type the “-Path” parameter and provide it with the individual certificate address.
  • Finally, execute the stated variable alongside the pipeline “|” and “fl” (Format-List) cmdlet:

Example 5: Export a Single Certificate

To export a single certificate, simply run the provided command:

$cert = Get-ChildItem -Path Cert:\CurrentUser\My\59722429099E950F29845B876F7585F46BE8F2D9

$cert | Export-Certificate -FilePath C:\Docs\New.cer

According to the above-stated code:

  • Specify the certificate, assigned variable, and the “|” pipeline.
  • Then, mention the “Export-Certificate” cmdlet.
  • Lastly, type the “-FilePath” parameter and provide it with the target file name and path:

That’s all! We have explained the management of Windows PowerShell certificates.

Conclusion

PowerShell has a certificate provider or manager that helps to manage certificates. Its management includes adding, deleting, exporting, or altering the certificates. This article has overviewed a detailed procedure to manage certificates in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.