1

I am trying to get a list where the title does not have temp or temporary or *contractor or contractor*.

This code is working, meaning I get a list which does not have temporary records.

$pTitle = $profile["Title"]
if ($pTitle -ne "Temporary")

However the following code does not work when I add -or and -notlike for the wildcard.

$pTitle = $profile["Title"]
if ($pTitle -ne "Temporary" -or $pTitle -notlike "Temporary" -or $pTitle -notlike "contractor" -or $pTitle -notlike "Temp")
3
  • try using "*text*" in -notlike condition Commented Jun 3, 2014 at 14:26
  • That did not help. The list still contains temporary, contractor records. if($pTitle -ne "Temporary" -or $pTitle -notlike "temporary" -or $pTitle -notlike "contractor" -or $pTitle -notlike "temp") Commented Jun 3, 2014 at 14:34
  • my bad the -notlike works solo but it fails with OR operator. Commented Jun 3, 2014 at 14:48

2 Answers 2

2

You actually want -and here. Your expression will only evaluate to false if all of the words are found currently.

Sign up to request clarification or add additional context in comments.

1 Comment

FERRIL: Just figured this out. Thanks if($pTitle -notlike "Temporary" -AND $pTitle -notlike "contractor" -AND $pTitle -notlike "Temp")
0
$List  = @(1,2,3)

If I ask you to return all the items in the list that are:
not equal to 1
or
not equal to 2
or
not equal to 3

the answer will be the whole list

$List  | where { ($_ -ne 1) -or ($_ -ne 2) -or ($_ -ne 3) }
1
2
3

You are getting your logical operators mixed up. Look at replacing -or with -and

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.