Importing a .pfx-file to IIS using Powershell is pretty straight forward thanks to guidelines such as this one Use PowerShell to install SSL certificate on IIS. But I do run into an issue when trying to bind port 443 using the imported certificate:
This due to "...If you don't already have a cer version, or you do but it includes the private key, enable Allow this certificate to be exported..." (ref. Setup of SharePoint 2013 High-Trust On-premise Add-In Developer / Production environment)
This is how it is set in the GUI
But, looking at the following line in the code which I got from dejanstojanovic.net.
pfx.Import($certPath,$certPass,"Exportable,PersistKeySet")   
it is set to Exportable. Removing PersistKeyset does not make a difference. So what could causing this?
- The script is not able to set it to Exportable as in the GUI "Allow this certificate to be exported"
 - ...I'm all out of options...
 
Update
I did tweak the code a bit, using constants and such, but still same issue
$certPath = "D:\ssl\cert-export-to-iis-10.pfx"  
$certPass = "password"  
$pfx = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2  
$KeyStorageFlags =     [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable -bxor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet
$pfx.Import($certPath,$certPass,$KeyStorageFlags)   
$store = New-Object     System.Security.Cryptography.X509Certificates.X509Store("WebHosting","LocalMachine")  
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)  
$store.Add($pfx) 
$store.Close()   
$store.Dispose()  
