Retrieves a list of all the published certificates assigned to the MyerKen user account.
On Error Resume NextConst E_ADS_PROPERTY_NOT_FOUND = &h8000500DConst ForWriting = 2Const WshRunning = 0Set objUser = GetObject _("GC://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")objUser.GetInfoEx Array("userCertificate"), 0arrUserCertificates = objUser.GetEx("userCertificate")If Err.Number = E_ADS_PROPERTY_NOT_FOUND ThenWScript.Echo "No assigned certificates"WScript.QuitElseSet objShell = CreateObject("WScript.Shell")Set objFSO = CreateObject("Scripting.FileSystemObject")strPath = "."intFileCounter = 0For Each arrUserCertificate in arrUserCertificatesstrFileName = "file" & intFileCounterstrFullName = objFSO.BuildPath(strPath, strFileName)Set objFile = objFSO.OpenTextFile(strFullName, ForWriting, True)For i = 1 To LenB(arrUserCertificate)ReDim Preserve arrUserCertificatesChar(i - 1)arrUserCertificatesChar(i-1) = Hex(AscB(MidB(arrUserCertificate, i, 3)))NextintCounter=0For Each HexVal in arrUserCertificatesCharintCounter=intCounter + 1If Len(HexVal) = 1 ThenobjFile.Write(0 & HexVal & " ")ElseobjFile.Write(HexVal & " ")End IfNextobjFile.CloseSet objFile = NothingSet objExecCmd1 = objShell.Exec _("certutil -decodeHex " & strFileName & " " & strFileName & ".cer")Do While objExecCmd1.Status = WshRunningWScript.Sleep 100LoopSet objExecCmd1 = NothingSet objExecCmd2 = objShell.Exec("certutil " & strFileName & ".cer")Set objStdOut = objExecCmd2.StdOutSet objExecCmd2 = NothingWScript.Echo VbCrLf & "Certificate " & intFileCounter + 1While Not objStdOut.AtEndOfStreamstrLine = objStdOut.ReadLineIf InStr(strLine, "Issuer:") ThenWScript.Echo Trim(strLine)WScript.Echo vbTab & Trim(objStdOut.ReadLine)End IfIf InStr(strLine, "Subject:") ThenWscript.Echo Trim(strLine)WScript.Echo vbTab & Trim(objStdOut.ReadLine)End IfIf InStr(strLine, "NotAfter:") ThenstrLine = Trim(strLine)WScript.Echo "Expires:"Wscript.Echo vbTab & Mid(strLine, 11)End IfWendobjFSO.DeleteFile(strFullName)objFSO.DeleteFile(strPath & "\" & strFileName & ".cer")intFileCounter = intFileCounter + 1NextEnd If
This is a VB Script, this can be used by saving the file in .vbs file