3

when i am trying to execute the below PowerShell command, i got error .

The command :

*PS cert:\currentuser\authroot> gci | where subject -like "UTN"*

The error is below :

Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "subject" value of type "System.String" to type "System.Management.Automation.ScriptBlock". At line:1 char:12 + gci | where <<<< subject -like "UTN" + CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand

I am using windows PowerShell ISE.
a workable solution is highly appreciated

8

It looks like you are using PowerShell Vs.2, that version had no support for the new where syntax.

In version 1 and 2 of PowerShell use:

gci | where {$_.subject -like "UTN"}

You need to put curly brackets around the expression and refer to any properties with the $_. prefix.

0

Peter Hahndorf has already answered this, but I wanted to expand on the error message you received:

Cannot convert the "subject" value of type "System.String" to type System.Management.Automation.ScriptBlock"

This is saying that it can't convert a string into a scriptBlock, which implies that where needs to be followed by a script block like so: {code here}

Be sure to read the error messages and try to interpret what they mean.

0

Use "-match" to find UTN that could be anywhere in the subject

gci | ?{$_.subject -match "UTN"}

If you use "-like" and nothing shows up, put what you're looking for between asterisks inside of quotes.

gci | ?{$_.subject -like "*UTN*"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.