Casper
Casper

Reputation: 157

Making an "and" statement to match more than 1 value

I got this part of a script

| Where {$_.property = statement}

I would like to add another value so that it has to match both values, so the command is going to work kinda like this

| Where {$_.property -eq statement} &  {$_.anotherproperty -eq anotherstatement}

anyone who can help?

Upvotes: 7

Views: 48733

Answers (2)

Lee
Lee

Reputation: 144206

Logical and is done using -and in powershell:

| Where {$_.property -eq statement -and $_.anotherproperty -eq anotherstatement}

Upvotes: 22

RB.
RB.

Reputation: 37222

The syntax you are looking for is -and and -or.

This example prints "Hello" if the variable a is greater than 9 and less than 11.

$a = 10
if ($a -gt 9 -and $a -lt 11) { Write-Host "Hello" }

Please see the documentation for more details.

Upvotes: 4

Related Questions