Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

where-object with two condition doesn't work in comparison statement form

$
0
0

hi friends

when i run this command in script block mode, it works fine:

Get-service |where{ $_.Name-like 'win*'-and $_.Status-eq 'running'}

 

but if i run the the same code in the comparison statement form, it fails

 

Get-service |whereName-like 'win*'-andStatus-eq 'running'

Where-Object : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:14
+   cls; gsv | ? Name -like 'win*' -and  Status -eq 'running'
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.WhereObjectCommand

 

is it a general rule that when we want to specify more than one condition in where -obect clause, we have to use script block form & we can't use comparison statement?

thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles