Export a List of all AD users Certificates from Each user

Roland S 26 Reputation points
2021-04-08T09:01:50.05+00:00

Hi,

I had to have export the User X509 Certificates from each User in a specific OU, with the Issuer and the Expiration Date.

the Export should be looks like in the AD User Object unter Published Certificates Tab.

thank you in advanced

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,862 questions
0 comments No comments
{count} vote

Accepted answer
  1. Daisy Zhou 28,906 Reputation points Microsoft Vendor
    2021-04-14T03:03:59.73+00:00

    Hello @Roland S ,

    You can try the PS script below.

    $ou = "ou=laps1,dc=b,dc=local"  
     $path ="C:\certs"  
     get-aduser -SearchBase $ou -Filter * -Properties displayname,usercertificate |ForEach-Object{  
        $displayname = $_.displayname  
        $_|select -ExpandProperty usercertificate | ForEach-Object{  
            $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]$_  
            [pscustomobject]@{  
                DisplayName = $displayname  
                IssuedTo = $cert.Subject  
                IssuedBy = $cert.Issuer  
                IntendedPurpose = $cert.EnhancedKeyUsageList  
                ExpiredData = $cert.NotAfter  
                SerialNumber = $cert.SerialNumber  
           }  
        }  
     } | Export-Csv -NoTypeInformation $path\certs.csv  
    

    Here is the result:
    87553-display1.png

    --please don't forget to Accept as answer if the reply is helpful--

    Best Regards,
    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    6 people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Daisy Zhou 28,906 Reputation points Microsoft Vendor
    2021-04-09T03:40:44.267+00:00

    Hello @Roland S ,

    Thank you for your posting here.

    After lots of test in my lab, I can get the result as below.

    1.Here is my OU named LAPS1, there are three users in it.
    86047-ps2.png

    2.Open Powershell ISE(run as administrator) and type the command below.

    $ou = "ou=laps1,dc=b,dc=local"  
    $path ="C:\certs"   
    get-aduser -SearchBase $ou -Filter * -Properties usercertificate |ForEach-Object{  
     $_|select -ExpandProperty usercertificate | ForEach-Object{  
         [System.Security.Cryptography.X509Certificates.X509Certificate2]$_  | select -Property Serialnumber, EnhancedKeyUsageList, notafter, notbefore, issuer, subject  
    
    } | Export-Csv -NoTypeInformation $path\$($_.name)_certs.csv  
    }  
    

    85998-ps1.png

    Tip:Please change the OU name and domain name and export path based on your AD environment.

    3.We can see one csv file for one user
    86017-ps5.png

    4.For example: we can see cert list for daisy11 and daisy22.
    Daisy 11
    85999-ps3.png

    Daisy22
    86000-ps4.png
    You can try the PS command in your AD environment.

    Hope the information above is helpful.

    Should you have any question or concern, please feel free to let us know.

    Best Regards,
    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    2 people found this answer helpful.
    0 comments No comments

  2. Daisy Zhou 28,906 Reputation points Microsoft Vendor
    2021-04-12T04:04:45.897+00:00

    Hello @Roland S ,

    Thank you for your update.

    We can run PS script below.

    $ou = "ou=laps1,dc=b,dc=local"  
    $path ="C:\certs"   
    get-aduser -SearchBase $ou -Filter * -Properties usercertificate |ForEach-Object{  
     $_|select -ExpandProperty usercertificate | ForEach-Object{  
         [System.Security.Cryptography.X509Certificates.X509Certificate2]$_  | select -Property Serialnumber, EnhancedKeyUsageList, notafter, notbefore, issuer, subject  
      
    }  
    } | Export-Csv -NoTypeInformation $path\certs.csv   
    

    Tip: Change the last line.

    The result (all users certificates within the OU in the same Excel file):
    86722-vv1.png

    Best Regards,
    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    2 people found this answer helpful.
    0 comments No comments

  3. Roland S 26 Reputation points
    2021-04-09T11:02:50.567+00:00

    Hi @Daisy Zhou ,

    Many Many Thanks to you , it looks great , it works Well.

    when i need all Certificate Lines in one Excel sheet, which Line is to change ?

    Many thanks in advanced

    Br
    Roland

    0 comments No comments

  4. Roland S 26 Reputation points
    2021-04-12T13:38:18.977+00:00

    Hi @Daisy Zhou ,

    Thanks a lot, it looks Good , one more think please can you add in the CSV Export please the Displayname from the AD User, like the Attached Picture , is eaisier to identify the User Object and their installed Certificates , and then it would be Perfect , and a lot of Thanks to you for your Support.

    86940-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.