@@ -12,13 +12,29 @@ param(
12
12
[Security.Principal.WindowsBuiltInRole ]::Administrator)
13
13
) {
14
14
Write-Progress - Activity " Gathering an EK Certificate" - CurrentOperation " Accessing the TPM" - PercentComplete 10
15
- $data = (Get-TpmEndorsementKeyInfo ).ManufacturerCertificates[0 ].GetRawCertData()
16
- Write-Progress - Activity " EK Certificate Gathered" - CurrentOperation " Converting to Base64" - PercentComplete 75
17
- $base64 = [Convert ]::ToBase64String($data , ' InsertLineBreaks' )
18
- Write-Progress - Activity " EK Certificate Gathered" - CurrentOperation " Writing PEM" - PercentComplete 90
19
- $pem = (" -----BEGIN CERTIFICATE-----`n $base64 `n -----END CERTIFICATE-----" ).Replace(" `r`n " , " `n " )
20
- [IO.File ]::WriteAllText($filename , $pem )
21
- Write-Progress " Done" - PercentComplete 100
15
+ $data = $null
16
+ $manufacturerCerts = (Get-TpmEndorsementKeyInfo ).ManufacturerCertificates
17
+ if ($manufacturerCerts -ne $null -and $manufacturerCerts.Length -gt 0 )
18
+ {
19
+ $data = $manufacturerCerts [0 ].GetRawCertData()
20
+ } else {
21
+ $additionalCerts = (Get-TpmEndorsementKeyInfo ).AdditionalCertificates
22
+ if ($additionalCerts -ne $null -and $additionalCerts.Length -gt 0 ) {
23
+ $data = $additionalCerts [0 ].GetRawCertData()
24
+ }
25
+ }
26
+
27
+ if ($data -eq $null ) {
28
+ echo " Found no EK Certificates using the PowerShell TrustedPlatformModule module."
29
+ $data = $null
30
+ } else {
31
+ Write-Progress - Activity " EK Certificate Gathered" - CurrentOperation " Converting to Base64" - PercentComplete 75
32
+ $base64 = [Convert ]::ToBase64String($data , ' InsertLineBreaks' )
33
+ Write-Progress - Activity " EK Certificate Gathered" - CurrentOperation " Writing PEM" - PercentComplete 90
34
+ $pem = (" -----BEGIN CERTIFICATE-----`n $base64 `n -----END CERTIFICATE-----" ).Replace(" `r`n " , " `n " )
35
+ [IO.File ]::WriteAllText($filename , $pem )
36
+ Write-Progress " Done" - PercentComplete 100
37
+ }
22
38
}
23
39
Else {
24
40
echo " Not admin"
0 commit comments