Install Certificates

23/01/2012 22:58



#install certificates

#source folder for certificates
$DestDir="C:\GBP.Install"

#set of certificates
$certificates=@("first.cer", "second.der", "third.cer", "fourth.der")

foreach($c in $certificates)
{
    $fileWithoutExtension=$c.substring(0, $c.lastIndexOf("."))
    #write-host "Meno suboru: "$fileWithoutExtension
   
    $MyReqCertificate=Get-SPTrustedRootAuthority|where-object {$_.Name -eq $fileWithoutExtension}
    if($MyReqCertificate -eq $null)
    {
           Write-host 'Installing certificate'
           $rootca = New-Object System.Security.Cryptography.x509Certificates.x509Certificate2($DestDir+ “\” + $c)
           New-SPTrustedRootAuthority –Name $fileWithoutExtension –Certificate $rootca
           Write-host $fileWithoutExtension 'certificate is installed'
    }
    else
    {
        write-host $MyReqCertificate.Name " is already installed."
    }
        
    
}