IIS 10 - Import SSL certificate using Powershell - "A specified logon session does not exist"

0

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:

Error: "A specified logon session does not exist. It may already have been terminated. (Exception from HRESULT: 0x80070520)".

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

enter image description here

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?

  1. The script is not able to set it to Exportable as in the GUI "Allow this certificate to be exported"
  2. ...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()  
powershell
ssl
iis
asked on Stack Overflow Dec 1, 2019 by rhellem • edited Dec 1, 2019 by rhellem

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0