I have have tried the following ways to import a certificate to the localmachine store via PowerShell. The console was running as administrator.
Import-PfxCertificate -Exportable -Password (secure.string) -CertStoreLocation Cert:\LocalMachine\My -FilePath 'certificatepath.pfx'
I also tried
$PFXFile = certificatepath.pfxc
$PFXPassword = secure.string
$PFXObject = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2($PFXFile, $PFXPassword, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$CertificateStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store('My','LocalMachine')
$CertificateStore.Open('MaxAllowed')
$CertificateStore.Add($PFXObject
$CertificateStore.Close()
This issue is this, neither method works. In both instances it does show up in the LocalMachine store, but it looks like there is private key associated with it even though the PFX file does have it.
If I import this same file via the MMC console, it loads fine. Via PowerShell, the following Event Appears
Level: Error
Source: Schannel
Event Id: 36870
Message: A fatal error occurred when attempting to access the TLS server credential private key. The error code returned from the cryptographic module is 0x8009030D. The internal error state is 10001.
Additional info: If I do a Get-Item on a certificate imported via MMC, the property PrivateKey does have information listed there. Imported via PowerShell and it's not there.
The OS is Server 2019 if that matters.