Get thumbprint of a certificate
You can use Select-Object
to get only the Thumbprint
-property:
Get-ChildItem -Path Cert:\LocalMachine\My |
Where-Object {$_.Subject -match "XXXXXXX"} |
Select-Object -ExpandProperty Thumbprint
All you have to do is wrap the command in parentheses, and then use dot-notation to access the Thumbprint
property.
Try this out:
$Thumbprint = (Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Subject -match "XXXXXXX"}).Thumbprint;
Write-Host -Object "My thumbprint is: $Thumbprint";
If you get multiple certificates back from your command, then you'll have to concatenate the thumbprints into a single string, perhaps by using the -join
PowerShell operator.
$Thumbprint = (Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Subject -match "XXXXXXX"}).Thumbprint -join ';';
Write-Host -Object "My thumbprints are: $Thumbprint";