I have some build scripts that generates certificates using CertMgr.exe, however I currently have to manually use the MMC snap-in, navigate to the certificate in question, right click it, select all tasks, select manage private keys, and then set the permissions manually. (For now, I just add Everyone and grant full permissions).
So I run the following script and then goto MMC and look for MACHINE-NAME Root CA
and then modify the permission manually. How can I modify my script so I don't have to do this manual step?
param([String]$CertName=$env:COMPUTERNAME)
$CertAuthName= $CertName + " Root CA"
Get-ChildItem cert:\ -DNSNAME $($CertAuthName + "*") -Recurse | Remove-Item
Get-ChildItem cert:\ -DNSNAME $($CertName + "*") -Recurse | Remove-Item
Remove-Item $CertName"*"
Remove-Item $CertAuthName"*"
.\makecert.exe -n $("CN="+$CertAuthName) -r -sv $($CertAuthName+".pvk") $($CertAuthName+".cer") >$null 2>&1
.\makecert.exe -crl -n $("CN="+$CertAuthName) -r -sv $($CertAuthName+".pvk") $($CertAuthName+".crl") >$null 2>&1
.\CertMgr.Exe -add -c $($CertAuthName+".cer") -s -r localMachine root >$null 2>&1
.\CertMgr.Exe -add -crl $($CertAuthName+".crl") -s -r localMachine root >$null 2>&1
.\makecert.exe -sk $CERTNAME -n $("CN="+$CERTNAME) $($CERTNAME+".cer") -iv $($CertAuthName+".pvk") -ic $($CertAuthName+".cer") -sr localmachine -ss my -sky exchange -pe >$null 2>&1