Register
: :
Login
Home
Forums
Blogs
Podcast
Directories
Scripts
Downloads
Community
User Group Support
Learning Resources
We have a new sponsor! Introducting
Pragma Systems
. See the home page for details.
Unanswered
Active Topics
Forums
Search
Members
Forums
>
Using PowerShell
>
General PowerShell
find all files not containing string
Last Post 08 Feb 2010 10:09 AM by
Shay
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
ittayd
New Member
Posts:2
08 Feb 2010 08:17 AM
How do I get a list of all files (recursively) that don't contain a specific string? Thank you, Ittay
Shay
Veteran Member
Posts:1136
08 Feb 2010 08:29 AM
One way:
Get-ChildItem
-Filter *.txt -Recurse | Where-Object { [io.file]::ReadAllText($_.FullName) -notmatch 'pattern' }
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter:
@ShayLevy
Shay
Veteran Member
Posts:1136
08 Feb 2010 08:38 AM
Or:
Get-ChildItem -Filter *.txt -Recurse | Where-Object { !(Select-String -Path $_.fullname -Pattern 'pattern' -SimpleMatch -Quiet)}
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter:
@ShayLevy
ittayd
New Member
Posts:2
08 Feb 2010 09:57 AM
Thanks!
And if I want to get a flat list of all file names?
Shay
Veteran Member
Posts:1136
08 Feb 2010 10: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://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter:
@ShayLevy
You are not authorized to post a reply.
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
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
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.1
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008