Created
January 30, 2019 20:01
-
-
Save ignas-sakalauskas/28dd064019f7d0797d90d5d7e74343ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on # https://social.technet.microsoft.com/wiki/contents/articles/28753.powershell-trick-copy-certificates-from-one-store-to-another.aspx | |
$SourceStoreScope = 'LocalMachine' | |
$SourceStorename = 'My' | |
$CertificateSubjectPattern = '*mytestdomain' | |
Write-Host 'Looking for certificates with subject' $CertificateSubjectPattern 'in' $SourceStoreScope'\'$SourceStorename | |
$SourceStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $SourceStorename, $SourceStoreScope | |
$SourceStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly) | |
$cert = $SourceStore.Certificates | Where-Object -FilterScript { | |
$_.subject -like $CertificateSubjectPattern | |
} | |
Write-Host 'Certificate(s) found:' | |
Write-Host $cert.subject | |
$DestStoreScope = 'LocalMachine' | |
$DestStoreName = 'Root' | |
$DestStore = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Store -ArgumentList $DestStoreName, $DestStoreScope | |
$DestStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) | |
$DestStore.Add($cert) | |
$SourceStore.Close() | |
$DestStore.Close() | |
Write-Host 'Certificate(s) added to:' $DestStoreScope'\'$DestStoreName | |
# https://ignas.me/tech/self-signed-multi-domain-ssl-certificate/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment