Created
April 12, 2022 06:09
-
-
Save MVKozlov/78173045299023310db8a44441107e27 to your computer and use it in GitHub Desktop.
Import self contained certificate into certificate store
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
#Cert content: | |
# PSv7 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -AsByteStream), 'InsertLineBreaks') | |
# PSv5.1 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -Encoding Byte), 'InsertLineBreaks') | |
$Cert = @" | |
MIILYgIBAzCCCx4GCSqGSIb3DQEHAaCCCw8EggsLMIILBzCCBjAGCSqGSIb3DQEHAaCCBiEEggYd | |
..... | |
/+1y1lZqkQICB9A= | |
"@ | |
#Cdert location: #LocalMachine, CurrentUser | |
$location = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser | |
#Storename: | |
#ls Cert:\CurrentUser\ | |
#ls Cert:\LocalMachine\ | |
$storeName = 'TrustedPublisher' | |
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new($storeName, $location) | |
$store.Open('ReadWrite') | |
[byte[]]$content = [Convert]::FromBase64String($cert) | |
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($content) | |
#$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($content, $password) | |
$store.Add($certificate) | |
$store.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment