Forum Discussion

TampaCCT's avatar
TampaCCT
Copper Contributor
Nov 02, 2020
Solved

Find all files inside directory Trees with a given name. Powershell question

I need help understanding the cmdlet behavior.      Simple command Get-ChildItem I want to find all the files in directories with a given name.    Example Data: c:\temp\AD\File1.txt c:\temp\AD...
  • farismalaeb's avatar
    farismalaeb
    Nov 05, 2020

    TampaCCT 

    This is the updated code 

    Set-location c:\
    Get-ChildItem -Include *.txt -Recurse | where {$_.FullName -like "*\AD\*"}

    you don't need to use the path if you already use set-location.

    the update here is adding the where filter to filter all the stream from the Get-ChildItem and check if in the full path of the result include a folder named AD.

    as you are scanning the entire root this should give you the result you are looking for. 

     

Resources