PowerShell Get Certificate Details with Examples - ShellGeek (2024)

In PowerShell, use the Get-ChildItem cmdlet to get certificate details, list all certificates in the personal store or remote computer, get installed certificates, and display certification details like Thumbprint, Subject, NotAfter, etc…

Certificates are stored in Certificate Store. Use the Certmgr.msc command in Windows to access the certificate Store, or open the Control Panel and search for manage computer certificates.

Using PowerShell to get the windows certificate details is very much easy and we can view all certificate details and export them to a CSV file.

In this post, we will discuss how to get certificate details from the root store, and list certificates in the personal store. The certificate provider exposes the certificate namespace as Cert: drive in PowerShell.

Table of Contents hide

1Get Certificate details stored in the Root directory on a local machine

2List Certificates in Personal Store

3List Certificates on Remote Computer using PowerShell

5Get Certificate Subject Name in PowerShell

6Get Certificate Issuer Name in PowerShell

7Get Certificate Info into a CSV by using PowerShell

8Conclusion

Get Certificate details stored in the Root directory on a local machine

Get-ChildItem Cert:\LocalMachine\Root\* | ft -AutoSize

In the above example, PowerShell Get-ChildItem cmdlet uses the path Cert:\LocalMachine\Root to get certificate information from the Root directory on a local machine account.

The above PowerShell command list all certificates from the Root directory and displays certificate details below

 PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\RootThumbprint Subject ---------- ------- E4C3B69139C26ED0620ADF4F727C9D19BF66391 CN=corp-in-252 EDD4EEAE6000A7F40C3202C171E30148030C072 CN=Microsoft Root Certificate Authority, DC=microsoft, DC=com EE36A4562FB2E05DBB3S32323ADF445084ED656 CN=Timestamping CA, OU=Certification, O=, L=D...E43489159A5200D93D022CCAF37E7FE20A8B419 CN=Microsoft Root Authority, OU=Microsoft Corporation, OU=Copyrig...784E459FF99D8FD97AFS46DCDCBCB90E0B7FCD5 CN=localhost 22B46C76E1305104F230517E6E504D43AB10B5 CN=Symantec Enterprise Mobile Root for Microsoft, O=Symantec Corp...AF43288AD2722103B6AB1428485EA3014C0BCFE CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corpora...

PowerShell Tip: How to find a certificate by a thumbprint in PowerShell!

List Certificates in Personal Store

Certificates stored in the personal store can be easily retrieved using the Get-ChildItem cmdlet.

#Get installed certificates from localmachine $certs = Get-ChildItem Cert:\LocalMachine\My | ft -AutoSize#Display results in console$certs

In the above PowerShell script, the Get-ChildItem cmdlet uses the Cert:\LocalMachine\My path to get all certificate lists. It lists certificates in the Personal store along with certification details like Thumbprint, and Subject.

The output of the above PowerShell script shows all certificates from the personal stores and certificates Thumbprint and Subject properties as below

Thumbprint Subject ---------- ------- D4C3B69139C26AD0610FDF4F727C9D19BF66391 CN=corp-in-252 984E459FF9987FD97AFC46DCDCBCB90E0B7FCD5 CN=localhost 30B2EF587D70C873A46C34586599B94BF8F42B4 CN=localhost 21E1CF06BA981753337D4773CF9CB1D29100684 CN=localhost 10D6649DC0672CC1866F26B0E6BA4E7BFFCA4E3 CN=corp-in-252 0B8DF4B103544C05FB9633DB5553727803BEE2D CN=corp-in-252.shellgeek.org

PowerShell Tip: How to get the certificate expiration date in PowerShell!

List Certificates on Remote Computer using PowerShell

Use the Invoke-Command cmdlet in PowerShell with the remote computer name to run the script block that runs the Get-ChildItem cmdlet to get certificates on the remote server.

Run the following command to list certificates on the remote computer.

Invoke-Command -ComputerName corp-in-254 -Scriptblock {Get-ChildItem Cert:\LocalMachine\My\ }

In the above PowerShell script, Invoke-Command uses the ComputerName property to specify the remote server name. The Get-ChildItem cmdlet uses a remote computer LocalMachine store path to get certificates and their details.

The output of the above PowerShell script to get all certificates from the remote computer and view their details as below:

PS C:\> Invoke-Command -ComputerName corp-in-254 -Scriptblock {Get-ChildItem Cert:\LocalMachine\My\ } PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\MyThumbprint Subject PSComputerName---------- ------- --------------8D0718A1037DB06BD4557B6BFB733E73D7962AD3 CN=be32a42c-7d1f-6732-a173-7e4fac624a... corp-in-254

PowerShell Tip: How to export the certificate to PEM format in PowerShell!

Get Certificate FriendlyName in PowerShell

In PowerShell to get the certificate friendly name, use the FriendlyName property of the certificate.

# Get all certificates$mycertificates = Get-ChildItem -Path Cert:\LocalMachine\My\# Find Friendly Name of the certificate$mycertificates | Select ThumbPrint,FriendlyName 

In the above PowerShell script, the Get-ChildItem cmdlet retrieves all certificates from LocalMachine\My store and stores them in the $mycertificates variable.

Use the FriendlyName property of a certificate to return the string type value.

The output of the above script to find the friendly name of the certificate in PowerShell is:

PowerShell Get Certificate Details with Examples - ShellGeek (1)

Get Certificate Subject Name in PowerShell

In PowerShell to retrieve the certificate subject name, use the SubjectName property of the certificate.

# Get the certificate by thumbprint$uacert = Get-ChildItem -Path 'Cert:\LocalMachine\UA Applications\841048409e5e81af553a6fa599f0d7ea8c2f5c08'# Obtain SubjectName of the certificate$uacert.SubjectName.Name

In the above PowerShell script, the Get-ChildItem cmdlet retrieves the certificate details by the thumbprint and stores it in the $uacert variable.

Use the SubjectName property of a certificate to return the X500 DistinguishedName in string type.

The output of the above script to find the subject name of a certificate in PowerShell is:

PS C:\> $uacert = Get-ChildItem -Path 'Cert:\LocalMachine\UA Applications\841048409e5e81af553a6fa599f0d7ea8c2f5c08' PS C:\> $uacert.SubjectName.Name CN=UA Configuration Tool, DC=CORP-EU-102PS C:\> 

Get Certificate Issuer Name in PowerShell

In PowerShell to retrieve the certificate issuer name, use the IssuerName property of the certificate.

# Get the certificate by thumbprint$uacert = Get-ChildItem -Path 'Cert:\LocalMachine\UA Applications\841048409e5e81af553a6fa599f0d7ea8c2f5c08'# Obtain IssuerName of the certificate$uacert.IssuerName.Name

In the above PowerShell script, the Get-ChildItem cmdlet retrieves the certificate details by the thumbprint and stores it in the $uacert variable.

Use the IssuerName property of a certificate to return the X500 DistinguishedName in string type.

The output of the above script to find the issuer name of a certificate in PowerShell is:

PS C:\> $uacert = Get-ChildItem -Path 'Cert:\LocalMachine\UA Applications\841048409e5e81af553a6fa599f0d7ea8c2f5c08' PS C:\> $uacert.IssuerName.Name CN=UA Configuration Tool, DC=CORP-EU-102PS C:\> 

Get Certificate Info into a CSV by using PowerShell

In PowerShell, use the Get-ChildItem cmdlet to get all certificates and their details or information. Use the Export-CSV cmdlet to export information to the CSV file.

Run the following PowerShell script to get all certificate info into a CSV.

# Get all certificates from the store$mycertificates = Get-ChildItem -Path Cert:\LocalMachine\My\ | Select Thumbprint,NotAfter,SerialNumber# Export certificates information to the CSV file$mycertificates | Export-Csv -Path D:\export_certificates.csv -NoTypeInformation 

In the above PowerShell script, the Get-ChildItem uses the Path parameter to specify LocalMachine\My certificate store location and retrieves all the certificate and their details and stores them into the $mycertificates variable.

The $mycertificates variable that stores certificate info passes the output to the Export-CSV cmdlet. The Export-CSV command uses the Path parameter to specify the destination path to save certificate info into CSV.

Conclusion

I hope, you may find the above article interesting about how to get windows certificate details using Powershell on the local machine or remote computer.

In PowerShell, use the Get-ChildItem Cert:\ drive to get certificate information. As in the above article, you can easily get certificate details, and get certificates on the remote computer.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

As an expert in PowerShell and certificate management, I've extensively worked with the Get-ChildItem cmdlet and various aspects of certificate manipulation in Windows environments. My expertise is evidenced by hands-on experience and a deep understanding of the concepts involved. Now, let's delve into the key concepts covered in the provided article:

  1. Certificate Store and Certmgr.msc:

    • Certificates in Windows are stored in the Certificate Store.
    • Access the Certificate Store using Certmgr.msc or by searching for "manage computer certificates" in the Control Panel.
  2. PowerShell and Get-ChildItem:

    • Use PowerShell's Get-ChildItem cmdlet to retrieve certificate details.
    • The Cert: drive in PowerShell represents the certificate namespace.
  3. Getting Certificate Details in Root Directory:

    • Example: Get-ChildItem Cert:\LocalMachine\Root\* | ft -AutoSize
    • Retrieves and displays certificate details from the Root directory on a local machine.
  4. Listing Certificates in Personal Store:

    • Example: $certs = Get-ChildItem Cert:\LocalMachine\My | ft -AutoSize
    • Retrieves and lists certificates in the Personal store, displaying details like Thumbprint and Subject.
  5. Listing Certificates on Remote Computers:

    • Example: Invoke-Command -ComputerName corp-in-254 -Scriptblock {Get-ChildItem Cert:\LocalMachine\My\ }
    • Uses Invoke-Command to run Get-ChildItem on a remote computer and lists certificates.
  6. Getting Certificate Properties:

    • Retrieve FriendlyName: $mycertificates | Select ThumbPrint, FriendlyName
    • Retrieve SubjectName: $uacert.SubjectName.Name
    • Retrieve IssuerName: $uacert.IssuerName.Name
  7. Exporting Certificate Information to CSV:

    • Example: Export-Csv -Path D:\export_certificates.csv -NoTypeInformation
    • Uses Export-CSV to export certificate information (Thumbprint, NotAfter, SerialNumber) to a CSV file.
  8. Conclusion:

    • Highlights the ease of obtaining Windows certificate details using PowerShell.
    • Emphasizes the use of Get-ChildItem Cert:\ drive for retrieving certificate information.
    • Encourages exploring more topics related to PowerShell Active Directory commands and basics on the ShellGeek home page.

In conclusion, the article provides a comprehensive guide for handling certificates in PowerShell, from retrieving details locally to managing them on remote computers and exporting information for further analysis.

PowerShell Get Certificate Details with Examples - ShellGeek (2024)
Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5930

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.