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

4

1 回答 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|...'
于 2013-03-18T22:05:59.323 回答