I am trying to write a powershell script to install a certificate in the certificate store of the active directory,
Here are the steps that need to be done manually; any help would be greatly appreciated.
On a Windows 2008R2 domain controller
Click "Start" β "Run"
type MMC
click ok
Click File β Add / Remove Snap-In
Choose "Certificates" β Add
Select "Service Account"
Click "Next"
Select "Local Computer"
Click "Next"
Select Active Directory Domain Services
Click Finish
Click ok
I want the script to install the certificate:
NTDS \ Personal
, , -, "", .
, , , powershell , β , , .
"NTDS\Personal" , $certRootStore localmachine CurrentUser, :/
function Import-PfxCertificate
{
param
(
[String]$certPath,
[String]$certRootStore = "localmachine",
[String]$certStore = "My",
$pfxPass = $null
)
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
if ($pfxPass -eq $null)
{
$pfxPass = read-host "Password" -assecurestring
}
$pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet")
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
$store.open("MaxAllowed")
$store.add($pfx)
$store.close()
}
Import-PfxCertificate -certPath "d:\Certificate.pfx"