PowerShell – Remove Lines Matching String

email me

Remove lines from text file that contain a specific string

Get-Content C:\_PowerShell\input.txt | Where-Object {$_ -notmatch 'Jackson'} | Set-Content C:\_PowerShell\output.txt


input.txt

Eddie
Jackson
Eddie
Jackson
Eddie
Jackson

output.txt
Eddie
Eddie
Eddie

 

Notes

Get-Content
Set-Content

 

tags: MrNetTek