Advertisement
tankcr

ImportCert

Aug 26th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. If ((Get-ChildItem -Path "Cert:\LocalMachine\root" | where-Object {$_.subject -like 'CN=PyrotekSACA*'})-eq $Null)
  2. {
  3.     $unccertpath = ($scriptspath + $CAName+'.cer')
  4.     While ("get-Childitem $unccertpath" -eq $NULL)
  5.     {
  6.         $MyWarning = "SSL Cert does not exist at the provided path $certpath please refer to documentation and ensure cert exists before continuing"
  7.         MSG
  8.         Pause
  9.     }
  10.     $certpath = "C:\Certs\"
  11.     copy $unccertpath $certpath
  12.     $certfile = "$certPath$CAName.cer"
  13.     $certRootStore = “LocalMachine”
  14.     $certStore = "Cert:\LocalMachine\root"
  15.     get-childitem cert:\LocalMachine\root | get-member
  16.     function Import-509Certificate
  17.     {
  18.         param([String]$certfile,[String]$certRootStore,[String]$certStore) $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
  19.         $pfx.import($certPath)
  20.         $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
  21.         $store.open(“MaxAllowed”)
  22.         $store.add($pfx)
  23.         $store.close()
  24.     }
  25.     Import-509Certificate
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement