$outFile = "C:\temp\issued-certs.csv" function Export-ADCSCertificates { param( [Parameter(Mandatory=$true)] [DateTime]$FromDate ) #region Filters $CVR_SEEK_EQ = 1 $CVR_SEEK_LT = 2 $CVR_SEEK_GT = 16 # Connecting to the Certificate Authority $objCertView = New-Object -ComObject CertificateAuthority.View $objCertView.OpenConnection("ADCS\ADCS-ADCS-CA") # Get a column count and place columns into the view $iColumnCount = $objCertView.GetColumnCount(0) $objCertView.SetResultColumnCount($iColumnCount) # Place each column in the view for ($x=0; $x -lt $iColumnCount; $x++) { $objCertView.SetResultColumn($x) } # Open the View and reset the row position $objCertViewRow = $objCertView.OpenView(); $objCertViewRow.Reset(); # Filter to only newer than date $index = $objCertView.GetColumnIndex($false, 'Certificate Effective Date') $now = Get-Date $objCertView.SetRestriction($index,$CVR_SEEK_LT,0,$now) $objCertView.SetRestriction($index,$CVR_SEEK_GT,0,$FromDate) #region Filter Only issued certificates # 20 - issued certificates $objCertView.SetRestriction($objCertView.GetColumnIndex($false, 'Request Disposition'),$CVR_SEEK_EQ,0,20) # Loop and export $headerRow = $true for ($x = 0; $objCertViewRow.Next() -ne -1; $x++) { # Columns with the info we need $certReq = @{} $objCertViewColumn = $objCertViewRow.EnumCertViewColumn() while ($objCertViewColumn.Next() -ne -1) { $certReq[$objCertViewColumn.GetName()] = $objCertViewColumn.GetValue(0) } if ($headerRow) { [PSCustomObject]$certReq | ConvertTo-Csv -NoTypeInformation | Select-Object -First 1 | Add-Content -Path $outFile $headerRow = $false } [PSCustomObject]$certReq | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Add-Content -Path $outFile } } If (Test-Path $outFile) { Remove-Item $outFile } Export-ADCSCertificates -FromDate (Get-Date -Date "2020-01-01 00:00:00Z")