Skip to content

Instantly share code, notes, and snippets.

@RaccoonDev
Created July 22, 2015 20:05
Show Gist options
  • Save RaccoonDev/b58af43c53e55e9c6687 to your computer and use it in GitHub Desktop.
Save RaccoonDev/b58af43c53e55e9c6687 to your computer and use it in GitHub Desktop.
<#
TODO:
1. Make the script to run itself with elevated permissions. Otherwise it can't open certificate store.
2. Take the certificate from some public place. Let's say blob.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True)]
[ValidateScript({
if(Test-Path -Path $_ -PathType Leaf -Include *.cer) {$True}
else { Throw "The $_ is not correct. Make sure that file exists and has CER extension." }
})]
[String]
$CertFilePath
)
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2;
$certificate.Import((Get-Item -Path $CertFilePath).FullName);
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store(
[System.Security.Cryptography.X509Certificates.StoreName]::Root,
[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine);
$store.Open("ReadWrite");
$store.Add($certificate);
$store.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment