I'm trying to write a PowerShell script that searches a network drive for a specific file name, and outputs all occurrences of the file in CSV format. For example, if I had a file called test.txt in folders c:\test\folder1 and c:\test\folder2, I want the CSV to list those two file paths, and the time each file was last modified.
Asked
Active
Viewed 5,017 times
-1
-
PowerShell scripts seem on-topic for SO. I edited the question to make it more clear. – RedGreenCode Jun 30 '14 at 19:07
-
And what is your specific question? – Barranka Jun 30 '14 at 19:28
-
Adding sample code will help a lot--otherwise it's likely your question will be closed – STW Jun 30 '14 at 19:35
1 Answers
1
get-childitem c:\test -Filter myfile.txt -rec | where {!$_.PSIsContainer} | select-object FullName, LastWriteTime | export-csv -notypeinformation -delimiter '|' -path c:\test\output.csv
This is based on the answers to Windows : How to list files recursively with size and last access date? and Recursive file search using PowerShell, with a few changes.

Community
- 1
- 1

RedGreenCode
- 2,195
- 1
- 25
- 33
-
This is a huge network drive with mulitple folders and subfolders. Will the excel sheet stop at a certain point or will everything get captured? – user3366898 Jun 26 '14 at 23:12
-
Everything will be captured, the only thing that may cause you issues is network latency causing time-outs since the larger the file system, the longer it will take to scan it all, and the longer it takes the more chance there is that there's a network hiccup and the process fails. What would be a better option, if you have it, would be to start a session on the server, perform the search, and have it report back to your current session, or output the data directly. – TheMadTechnician Jun 26 '14 at 23:15
-
Is is normal for cpu usage to dwindle down to 0%? this is about 600GB worth of data – user3366898 Jun 26 '14 at 23:43
-
i recieved this error: Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 26 0 characters, and the directory name must be less than 248 characters. HOW can i fix this? Thanks – user3366898 Jun 26 '14 at 23:52
-
This is a Windows limitation. The best answer is to change your directory structure to limit the amount of nesting, if you have control over it. If you can't do that, there are some tricks using drive mappings, as explained in http://social.technet.microsoft.com/Forums/scriptcenter/en-US/5bb8d044-ae62-44ce-a204-f0035131341d/getchilditem-the-specified-path-file-name-or-both-are-too-long-the-fully-qualified-file-name?forum=ITCG. – RedGreenCode Jun 27 '14 at 00:20