1
votes

I am using the below code:

Get-ChildItem -Path N:\USERS -Filter DANTOM.DTM -Recurse -ErrorAction SilentlyContinue -Force

I need it to either find the file "DANTOM.DTM" or the extension ".DTM". I need to exclude the folder N:\USERS\EDI because it is a 1.7TB folder that would never have this file in it. So in doing so would really speed up the process.

I would like the end result to either spit into a .txt file saying which folders inside of N:\USERS has the file or just have it display as a list in powershell.

Thank you,

1
So you just want GCI C:\Users\* -Directory -Exclude 'EDI' | %{GCI $_ -Include DANTOM.DTM -Recurse -Force -EA 0}|Set-Content "$home\desktop\DTM Location.txt"TheMadTechnician
I tried your code, It just sits and runs forever. No text file.Kevin Missildine

1 Answers

1
votes

Assuming that the files of interest do not reside directly in N:\USERS (only in subdirs.), try the following (PSv3+ syntax); send to a file by appending > dirs.txt, for instance.

Get-ChildItem N:\USERS -Directory | ? Name -ne 'EDI' | 
  Get-ChildItem -Recurse -Filter *.DTM | 
    ForEach-Object { $_.DirectoryName }

Note: While it is tempting to try a simpler approach with -Exclude EDI, it unfortunately doesn't seem to be effective in excluding the entire subtree of the EDI subfolder.