Search code examples
powershellcertificatex509certificatex509certificate2

Importing Certificates - Access denied (while run as administrator)


I'm working on automating the add of a certificate I created from Cert:\CurrentUser\My to Cert:\CurrentUser\TrustedPublisher so that I can use the AllSigned ExecutionPolicy. When I use the Import-PfxCertificate cmdlet (after exporting, obviously), I'm getting Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

The weird thing about all of this, I can go into the certificates MMC and import the certificate myself, but when trying to run it through PowerShell (as administrator), it's giving me the errors.


Solution

  • I found I was able to import the cert to the LocalMachine, but not CurrentUser.

    Import-PfxCertificate -FilePath 'Path\Cert.pfx' -Password (Get-Credential).Password -CertStoreLocation Cert:\LocalMachine\Root
    Import-PfxCertificate -FilePath 'Path\Cert.pfx' -Password (Get-Credential).Password -CertStoreLocation Cert:\LocalMachine\TrustedPublisher