Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ElanHasson/4c92b7dfc54f3950e0bb6596be66a055 to your computer and use it in GitHub Desktop.
Save ElanHasson/4c92b7dfc54f3950e0bb6596be66a055 to your computer and use it in GitHub Desktop.
ipmo PKI
$name = [GUID]::NewGuid()
$cerFile = "$env:TEMP\$name.cer"
$certs = Get-ChildItem Cert:\LocalMachine\My -DnsName localhost -SSLServerAuthentication | ? {($_.FriendlyName -eq 'IIS Express Development Certificate') -and ($_.SignatureAlgorithm.FriendlyName -ieq 'sha256RSA') -and ($_.EnhancedKeyUsageList.Count -eq 1)}
if ($certs.Count -eq 0)
{
Write-Error 'Cannot find any SHA256 certificate generated by IIS Express. Please make sure that the latest version of IIS Express is installed.'
}
else
{
foreach ($cert in $certs)
{
Export-Certificate -Cert $cert.PSPath -FilePath $cerFile -Type CERT | Out-Null
Import-Certificate -FilePath $cerFile -CertStoreLocation Cert:\CurrentUser\Root | Out-Null
Remove-Item $cerFile -Force
}
Write-Host 'Successfully installed the certificate to Trusted Root Certification Authorities of the current user.'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment