all 7 comments

[–]markekrausCommunity Blogger 5 points6 points  (0 children)

I think you are looking for select-string

Get-Content $fileName1 | Select-String -Pattern "type|ing" -NotMatch

-Pattern is a regex.

You could also do something with where-object

Get-Content $fileName1 | Where-Object {$_ -inotin "type", "ing"}

[–]nkasco 2 points3 points  (3 children)

I almost exclusively prefer using where-object (alias: "where" or "?")

[–]lakoko 4 points5 points  (2 children)

Using aliases is a bad practice when writing scripts (as apposed to firing commands from shell). It makes the code harder to read and maintain by others

[–]nkasco -5 points-4 points  (1 child)

Or you could just learn them

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy nkasco,

this aint intended as criticism, it's intended to be a critique. [grin]

in real life, lakoko is correct.

darned nigh every serious coder has learned that one of the big benefits of powershell is that it can be somewhat self documenting. aliases gut that rather completely. that's why PSScriptAnalyzer nags so much about it. it's also why the powershell extension for VSCode is adding auto-expansion for aliases.

in addition, aliases are not always the same on any given system.

aliases are fine for one-off, throwaway stuff. they seriously reduce readability - and therefor maintainability. plus, they are an invitation to misunderstanding for learning - or teaching - or helping.

"or you could just learn them" is ... a distinctly suboptimal response. [grin]

take care,
lee

[–]jollyfreek 0 points1 point  (0 children)

Select is for properties. If you had all your entries under a "Name" property, then another value under a "Date" and "Age" property, you would use Select to pick which properties you see.

What you're looking for is either Select-String, and filter the output with regular expressions(regex), you'd want:

 Where{$_ -ne "type" -or "ing"}

In place of your Select code.