Advertisement
tankcr

cert

Mar 26th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. If ((Get-ChildItem -Path "$certStore" | where-Object {$_.subject -like 'CN=CA-*.Pyrotek-Lab.local*'}| Sort-Object NotAfter -Desc | Select-Object -First 1)-eq $Null)
  2. {
  3.     ## Create Import Certificate Function
  4.     function Import-509Certificate
  5.     {
  6.         param([String]$certPath,[String]$certRootStore,[String]$certStore) $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
  7.         $pfx.import($certPath)
  8.         $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore)
  9.         $store.open(“MaxAllowed”)
  10.         $store.add($pfx)
  11.         $store.close()
  12.     }
  13.     # You should just fail here, and get them to run it again once they've fixed the problem
  14.     while ("get-Childitem $unccertpath" -eq $NULL)
  15.     {
  16.         Write-Log -type Warning "SSL Cert does not exist at the provided path $certpath please refer to documentation and ensure cert exists before continuing"
  17.         Pause
  18.     }
  19.     if ((Get-ChildItem -Path C:\|Where-Object{$_.Name -eq "Certs"}) -EQ $NULL){MD C:\Certs}
  20.     copy "$unccertpath" $certpath
  21.     Import-509Certificate "$certfile" "CurrentUser" "ROOT"
  22.     If ((Get-ChildItem -Path "$certStore" | where-Object {$_.subject -like 'CN=CA-*.Pyrotek-Lab.local*'}| Sort-Object NotAfter -Desc | Select-Object -First 1)-ne $Null)
  23.     {
  24.     Write-Log -type Success "Certificate "+ (Get-ChildItem -Path "$certStore" | where-Object {$_.subject -like 'CN=CA-*.Pyrotek-Lab.local*'}| Sort-Object NotAfter -Desc | Select-Object -First 1).Subject + " was successfully placed in the $certStore store"
  25.     }
  26.  
  27.     # get-childitem cert:\LocalMachine\root | get-member
  28. }
  29.  
  30. $certdir = dir "$certStore"
  31. # Update the binding with the certificate
  32. #dir "Cert:\LocalMachine\my"
  33. #dir "IIS:\SslBindings"
  34. $cert = "IIS:\SslBindings\0.0.0.0!443"
  35. $SSLBinding = "IIS:\SslBindings\0.0.0.0!443\"
  36. # Grab the Certificate thumbprint
  37. $certThumb = Get-ChildItem -Path "$certStore" | where-Object {$_.subject -like 'CN=CA-*.Pyrotek-Lab.local*'} | Sort-Object NotAfter -Desc | Select-Object -First 1 -expand Thumbprint
  38.  
  39. # Grab the Certificate and update the binding
  40. if ((get-Item -Path $cert)-ne $NULL)
  41. {
  42. Remove-Item -Path $cert
  43. }
  44. $i=0
  45. While ((get-item -path $cert) -eq $NULL -and($i -le 3))
  46. {
  47.     $i++
  48.     Write-Log -type Warning "The SSL Certificate must be bound to Central Administration Attempt $i"
  49.     Get-Item cert:\localmachine\CA\$certThumb|New-Item $SSLBinding
  50.     CD IIS:\SslBindings
  51.     get-item cert:\LocalMachine\CA\$certThumb | New-Item 0.0.0!443
  52. }
  53. if ((get-item -path $cert) -eq $NULL)
  54. {
  55.     Write-Log -type Error "The SSL Certificate was not successfully bound to Central Administration, halting install"
  56.     #Exit
  57. }
  58. Write-Log -type Success ("The SSL Certificate was successfully installed to " + (Get-Item $cert).Sites.Value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement