Powershell Select-object from cert store
certificate, powershell, powershell-2.0
Solution
Don't use `format-list`, you already have all the properties. `format-list` will convert your nice `X509Certificate2` object into a set of format objects which isn't what you want at all. Also use `-expandproperty` on the `select`:
PS>get-childitem | where { $_.subject -eq "CN=localhost" } | select -expandproperty SerialNumber
6191F4A438FF77A24763E6D427749CD7
Or with Powershell 3 or later, use the shorthand notation:
PS>$serno = (get-childitem | where { $_.subject -eq "CN=localhost" }).SerialNumber
PS>$serno
6191F4A438FF77A24763E6D427749CD7
Problem
Essentially I am trying to get the serial number of a certificate by using the subject so I can use it in a variable in CertUtil. I am so close yet so far as you will see below can anybody help please? ``` cd cert:\localmachine\my $serno = get-childitem | where { $_.subject -eq "XXXXXXXXXXXXXXXX" } | format-list -property * | select -property SerialNumber $serno ``` this displays ``` SerialNumber ------------ ``` not the actual serial number Does anybody have any clues??