Powershellによるインストール証明書のインポート機能スクリプトの共有

897 ワード

すべてのバージョンをサポートします.通常、ファイルから証明書をロードし、指定したライブラリにインストールします.次のスクリプトを使用できます.
 
  
$pfxpath = 'C:\temp\test.pfx'
$password = 'test'
[System.Security.Cryptography.X509Certificates.StoreLocation]$Store = 'CurrentUser'
$StoreName = 'root'
 
Add-Type -AssemblyName System.Security
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$certificate.Import($pfxpath, $password, 'Exportable')
 
$Store = New-Object system.security.cryptography.X509Certificates.x509Store($StoreName, $StoreLocation)
$Store.Open('ReadWrite')
$Store.Add($certificate)
$Store.Close()

このスクリプトを構成し、証明書の場所とパスワードを指定できます.また、現在のユーザーまたはローカルコンピュータの格納場所を指定し、信頼されているルート証明書などの証明書またはプライベート証明書を追加することもできます.