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

3 Answers 3

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
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*"} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.