Skip to content

Commit 6c21a3a

Browse files
committed
Powershell slightly expand ek retrieval and dont use wmic
1 parent eea889a commit 6c21a3a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

scripts/windows/allcomponents.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,10 @@ $componentArray=(jsonComponentArray "$componentChassis" "$componentBaseboard" "$
864864

865865
### Gather property details
866866
Write-Progress -Id 1 -Activity "Gathering properties" -PercentComplete 80
867-
$osCaption=((wmic os get caption /value | Select-String -Pattern "^.*=(.*)$").Matches.Groups[1].ToString().Trim())
867+
$osCaption=(Get-WmiObject -Class Win32_OperatingSystem).caption
868+
if ($osCaption -ne $null) {
869+
$osCaption = $osCaption.Trim()
870+
}
868871
$property1=(jsonProperty "caption" "$osCaption") ## Example1
869872
$property2=(jsonProperty "caption" "$osCaption") # "$JSON_STATUS_ADDED") ## Example2 with optional third status argument
870873

scripts/windows/get_ek.ps1

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@ param(
1212
[Security.Principal.WindowsBuiltInRole]::Administrator)
1313
) {
1414
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+
}
2238
}
2339
Else {
2440
echo "Not admin"

0 commit comments

Comments
 (0)