title: Export root certificate using powershell
body: <p>I am installing a client side certificate on a Windows 2012 server through Powershell.
  Installing a client side certificate requires two steps:</p>
  
  <ol>
  <li>Installing the certificate on the Personal Store ("my"). </li>
  <li>Installing the root certificate of that certificate in the Trusted
  Root Certification Authority Store.</li>
  </ol>
  
  <p>Step 1 is fairly easy.
  However, step 2 is tricky. First, I do not know the length of the chain of the certificate. When doing it by-hand, you need to go to export each certificate in the chain until you reach the root (you can only export the first element of the chain). Then, you install the root certificate in the Trusted Store.</p>
  
  <p>So, my question is: how do you get the root certificate of a certificate?
  My idea would be to get the certificate chain and somehow process it until you get the root certificate. Any ideas on how this can be done?</p>