derekhh February 2016

Get-ChildItem piping Where-Object in Powershell fails?

I'm trying to retrieve a certificate from my local certificate store. I started by doing something like this:

PS Cert:\CurrentUser\My> $cert = Get-ChildItem -Path Cert:\CurrentUser\My

PS Cert:\CurrentUser\My> $cert | Where-Object {$_.Thumbprint -Match "84437"}


Directory: Microsoft.PowerShell.Security\Certificate::CurrentUser\My


Thumbprint                                Subject                                                                                                                                                                                    
----------                                -------                                                                                                                                                                                    
8443700000000000000000000000000000000000  CN=some certificate

Well. This works. So I changed it to:

Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object {$_.Thumbprint -Match "‎84437"}

Yet this time I get no output at all. What's the root cause for this?

Answers


Micky Balladelli February 2016

The first double quote in "84437" in :

Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object {$_.Thumbprint -Match "‎84437"}

seems to contain 2 characters, try to delete it and you will see that you actually need to do it twice.

If we check that character using:

"`"‎".ToCharArray()|%{[int][char]$_}

The output is super weird:

34
8206

34 is the double quote, and 8206 is the weird stuff.

So just delete the double quote and and enter it again, it should work.

Post Status

Asked in February 2016
Viewed 2,134 times
Voted 14
Answered 1 times

Search




Leave an answer