1

I am finishing a last piece of this mini-app where I'm pulling names from a text file. When pulling the names from a ..txt I am filtering out certain prefixes like *eft, *nsm with code like below.

$lines = (Get-Content C:\temp\PROD\Repeat.txt  -totalcount 200)

$flines = $lines|?{$_ -notlike "*eft", "nsm*", "*" , "*" .... }

$objOutputBox.Text = $flines

The problem I'm having is that it is only grabbing the "*eft" and not the rest of them. I thought I could filter an array of strings with this structure? What am I missing here if you do not mind?

Thanks

1 Answer 1

4

You cannot apply -notlike like this. You'll have to use the operator multiple times:

-notlike '*eft' -notlike 'nsm*' ...

But a better way would probably be a regular expression:

-notmatch 'eft$|^nsm|...'
Sign up to request clarification or add additional context in comments.

2 Comments

You don't need the intermediate variable $flines there, though. You can just assign the pipeline to $objOutputBox.Text. Also, I hope the '*' arguments to -notlike were placeholders, not actual operands.
Okay I will pipeline it. Yeah they are placeholders.. Thanks again it is highly appreciated.

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.