Get thumbprint of a certificate
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";
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
Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Subject -match "XXXXXXX"}
This one will never work cause you are using $_.subject
you shall use $_.thumbprint
:
Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.Thumbprint -match "0F273F77B77E8F60A8B5B7AACD032FFECEF4776D"}