-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-NewestCertificateRequest.ps1
56 lines (50 loc) · 1.8 KB
/
Get-NewestCertificateRequest.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.Synopsis
Retrieve newest requestID received on the target Certificate Authority
.DESCRIPTION
Requires PSPKI PowerShell module
Uses certutil -view -restrict "$RequestID=$" to retrieve Newest request from the CA
https://blogs.technet.microsoft.com/pki/2008/10/03/disposition-values-for-certutil-view-restrict-and-some-creative-samples/
.EXAMPLE
Get-CA | Get-NewestCertificateRequest
.EXAMPLE
Get-CertificateAuthority "CA3" | Get-NewestCertificateRequest
#>
function Get-NewestCertificateRequest
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
param (
# requires PSPKI PowerShell module, creates a [PKI.CertificateServices.CertificateAuthority] object
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[PKI.CertificateServices.CertificateAuthority[]]$CertificateAuthority
)
begin {
}
process {
foreach ($CA in $CertificateAuthority)
{
try
{
# parse certutil output
$configString = $CA.ConfigString
$newestRequestID = certutil -view -restrict "RequestId=$" -config $configString -out RequestID
$newestRequestID = $newestRequestID -match "Issued Request ID\:"
$newestRequestID = $newestRequestID -replace "Issued Request ID\:",""
$newestRequestID = ($newestRequestID -split "\(")[1]
$newestRequestID = $newestRequestID -replace "\)",""
Write-Verbose "Found RequestID of newest certificate request on CA: $newestRequestID"
# output
$newestRequestID
}
catch
{
Write-Error $_
continue
}
}
}
end {
}
}