Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
General PowerShell
find all files not containing string
Last Post 08 Feb 2010 02:09 AM by
Shay Levy
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Ittay
New Member
Posts:2
08 Feb 2010 12:17 AM
How do I get a list of all files (recursively) that don't contain a specific string? Thank you, Ittay
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
08 Feb 2010 12:29 AM
One way:
Get-ChildItem
-Filter *.txt -Recurse | Where-Object { [io.file]::ReadAllText($_.FullName) -notmatch 'pattern' }
Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
08 Feb 2010 12:38 AM
Or:
Get-ChildItem -Filter *.txt -Recurse | Where-Object { !(Select-String -Path $_.fullname -Pattern 'pattern' -SimpleMatch -Quiet)}
Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
Ittay
New Member
Posts:2
08 Feb 2010 01:57 AM
Thanks!
And if I want to get a flat list of all file names?
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
08 Feb 2010 02:09 AM
Pipe the results to foreach-object and choose one of:
1. $_.Name (file name only)
2. $_.FullName (full path)
Get-ChildItem -Filter *.txt -Recurse | Where-Object { !(Select-String -Path $_.fullname -Pattern 'pattern' -SimpleMatch -Quiet)} | Foreach-Object {$_.Name}
Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2