Search code examples
powershell

Find files which does not contains selected string


I am trying to find all files, which does not contains a selected string. Find files which contains is easy:

gci | select-string "something"

but I do not have an idea how to negate this statement.


Solution

  • I'm not sure if it can be done without the foreach-object but this works:

    gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}}