Get filename that does not contain the specified string
i'm looking thru group of files in particular directory specified string, need file names not contain string. me true / false, without filename:
ls . -name incremental* | foreach {select-string -path $_ -pattern "->or_case`:" -quiet}
this 1 gets me filenames contain string:
ls . -name incremental* | foreach {select-string -path $_ -pattern "->or_case`:" | format-table -property filename}
is there way combine both? "format-table -property filename, equals" did not work, there's no value equals member or no value filename member if use -quiet in 'sls' cmdlet.
try this:
ls 'c:\temp' | select @{l='file';e={$_.name}}, @{l='string found?';e={if(select-string -path $_ -pattern "language" -quiet){write-output $true}else{write-output $false}}} result: file string found? ---- ------------- users ad.txt false bob.txt false configurationmanager.txt false data.txt false debug.txt true dummy.txt false hrfile.csv false lastmodified.txt false
in example 'users' folder. can exclude folders, or recurse needed, of course.
to filter further, add:
| where{-not ($_.'string found?')}
or similar, taste.
even more simple:
ls 'c:\temp' | where{-not(select-string -path $_ -pattern "language" -quiet)} | select fullname
just humble sysadmin
Windows Server > Windows PowerShell
Comments
Post a Comment