Exclude folders from search

Welcome Forums General PowerShell Q&A Exclude folders from search

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
3 years, 5 months ago.

  • Author
    Posts
  • #26792

    Participant
    Points: 0
    Rank: Member

    Hi All,

    I have this script :

    
    param(
        [string]$pattern,
        [string]$path  
        ) 
    $exclude = ("w:\test\york\SedAwk")
    Get-ChildItem -path $path -Recurse -Filter *.html | 
        Where-Object{
            ForEach-Object {
                If (Get-Content $_.FullName | Select-String -Pattern "Stay Connected") {
                    Select-String -InputObject (Get-Content $_.FullName | Where {$_.FullName -notlike $exclude} | Out-String) -Pattern "(?sm)

    But I am having a hard time getting it to exclude the SedAwk folder.

    How can this be achieved?

    Thanks

  • #26796

    Participant
    Points: 355
    Helping Hand
    Rank: Contributor

    Try this:

    Get-ChildItem -path $path -Recurse -Filter *.html -Exclude "*SedAwk*"
    

    Also, I'm not sure if you just threw the above together for an example, but the Where-Object is not correct in your statement.

The topic ‘Exclude folders from search’ is closed to new replies.