Reputation: 133
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
Upvotes: 1
Views: 66
Reputation: 354874
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|...'
Upvotes: 4