Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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