Get-Certificate doesn't find any certificates in [System.Security.Cryptography.X509Certificates.StoreName]::CertificateAuthority

Create issue
Issue #130 resolved
Alexander Groß created an issue

Get-Certificate uses the System.Security.Cryptography.X509Certificates.StoreName value to construct the PowerShell path below cert:\.

For [System.Security.Cryptography.X509Certificates.StoreName]::CertificateAuthority this leads to e.g. cert:\LocalMachine\CertificateAuthority but the actual path is cert:\LocalMachine\CA (CA is the certificate store's name as constructed by $(Get-CertificateStore -StoreLocation LocalMachine -StoreName CertificateAuthority).Name)

Comments (5)

  1. Alexander Groß reporter

    Why an if why not use the .Name property? What's when the next special StoreName comes along?

  2. Aaron Jensen repo owner

    What .Name property? On which object?

    If Microsoft adds a new StoreName value (not likely) and the PowerShell teams muffs the name again, I guess I'll convert the if statement to a lookup table. :(

  3. Alexander Groß reporter

    Since the $StoreName parameter is a Security.Cryptography.X509Certificates.StoreName you could to the following:

    $(Get-CertificateStore -StoreLocation $StoreLocation -StoreName $StoreName).Name
    

    Here's the snippet from a PS script:

    PS C:\Windows\system32> $storeName = [System.Security.Cryptography.X509Certificates.StoreName]::CertificateAuthority
    PS C:\Windows\system32> $store = Get-CertificateStore -StoreLocation LocalMachine -StoreName $storeName
    PS C:\Windows\system32> $store.Name
    CA
    
  4. Aaron Jensen repo owner

    I didn't know this. I'll leave it as-is for now. If I ever have to dive back in, I'll update the code to do this.

  5. Log in to comment