I have been tasked with automating installation of LetsEncrypt certficates on several Windows Server 2016 systems.
One requirement is to copy the ACL from the old private key to the new one, and so my script first identifies the unique container name from 'C:\ProgramData\Microsoft\Crypto'
.
Assuming that I have set the value of $Thumbprint to the correct certifciate thumbprint - which I have... then I believe should be able to locate the private key in the filesystem using:
(Get-Item "CERT:\LocalMachine\My\$Thumbprint").PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
This works great when I import the PFX using certlm.msc but not when I have imported the PFX using Powershell Import-PFXCertificate
?
When imported using this cmdlet the .HasPrivateKey
property is True, but the .PrivateKey property itself is empty.
I have the script working using certutil with the -ImportPfx
switch which is ok, however will not accept the SecureString password.
Any help or ideas would be much appreciated.
To mods:
Symptoms here are the same as this > (PowerShell Import Pfx, and Private Key "Lost"), however the conditions are not. I am not defining my own function to import the PFX, I am using the native Powershell cmdlet Import-PfxCertificate (https://learn.microsoft.com/en-us/powershell/module/pki/import-pfxcertificate?view=windowsserver2016-ps) and therefore am unable to edit the x509 flags as described in that resolution.