Search code examples
algorithmpowershellsha1

How to get a security hash algorithm for a certificate using Powershell


I need to get a list of all the certificates with a particular hash algorithm.

First I tried retrieving SignatureAlgorithm as follows:

Get-ChildItem -Recurse | select thumbprint, subject, SignatureAlgorithm

Which gave me System.Security.Cryptography.Oid as a value of SignatureAlgorithm column

I tried using FriendlyName

Get-ChildItem -Recurse | select thumbprint, subject, SignatureAlgorithm.FriendlyName

But the above returned blank as a value for SignatureAlgorithm

How can I retrieve the readable value of SignatureAlgorithm? And also how do I select all the SHA1 certificates using Powershell?


Solution

  • Select-Object are expecting names for the properties to show (since you didn't specify a parameter, you're using the 1st pos. which is -Property). There are no properties called SignatureAlgorithm.FriendlyName.

    If you use a calculated property, you can design your own property where the value is the property FriendlyName inside the object's SignatureAlgorithm-property. Ex:

    Get-ChildItem -Recurse | select thumbprint, subject, @{n="SignatureAlgorithm";e={$_.SignatureAlgorithm.FriendlyName}}
    

    (n is short for name (could also use l or label) and e is short for expression)