• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12027
  • Last Modified:

Powershell script to find files on network computers.

I am in need of a Powershell script to locate specified files on network (domain) computers.  I need to determine the computer, size, and location of the file if found.  I have 40 files to look for and they are of varying type.  I do have the exact name for each file.

If necessary, I can run the script 40 times, but would prefer a more complete solution.

Thank you.
1
mobanker
Asked:
mobanker
1 Solution
 
Joshua GrantomSystems AdministratorCommented:
are you just searching in shares or or you trying to search the entire hard drive of every computer on the network?
0
 
mobankerAuthor Commented:
Searching the entire drive.  Drives C: and D: should cover everything.

Thank you!
0
 
Joshua GrantomSystems AdministratorCommented:
Here you go, This will take a very long time to run, I would run it from a server and leave it. Unfortunately there is no quick way to search every harddrive on a network. You will need to run this with a Domain Admin Account.

$computers = Get-ADComputer -filter *  | Select -Exp Name

$filenames = Get-Content "C:\filenamelist.txt"

foreach ($computer in $computers) {

foreach ($filename in $filenames) {
Get-ChildItem -Recurse -Force \\$computer\c$ -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and  ( $_.Name -eq "$filename") } | Select-Object Name,Directory| Export-Csv C:\FoundFiles.csv -nti -append
}
}

Open in new window


You need to add each file you are looking for on a single line in a text file name filenamelist.txt in your c drive. It will export a csv file on your C drive named FilesFound.csv
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
mobankerAuthor Commented:
A thing a beauty!  Thank you for your help Joshua.
0
 
Joshua GrantomSystems AdministratorCommented:
That was just for the C drive btw.

Just add this line below the other get-childitem

Get-ChildItem -Recurse -Force \\$computer\d$ -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and  ( $_.Name -eq "$filename") } | Select-Object Name,Directory| Export-Csv C:\FoundFiles.csv -nti -append

Open in new window

0
 
mobankerAuthor Commented:
Thank you, I am running it now.  I had a little issue with the c:\filenamelist.txt getting named c:\filename.txt.txt which threw some permission errors.  Once I fixed that, it is running and returning results properly.

I will add that line and re-start!
0
 
Joshua GrantomSystems AdministratorCommented:
This is a better version for future reference

$computers = Get-ADComputer -filter *  | Select -Exp Name

$filenames = Get-Content "C:\filenamelist.txt"

foreach ($computer in $computers) {

foreach ($filename in $filenames) {
Get-ChildItem -Recurse -Force \\$computer\c$, \\$computer\d$ -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and  ( $_.Name -eq "$filename") } | Select-Object Name,Directory| Export-Csv C:\FoundFiles.csv -nti -append
}
}

Open in new window

0
 
mobankerAuthor Commented:
It is running!  Have a great day and thank you very much.
0
 
Member_2_7971328Commented:
Joshua,

I know this post is older, but is there any way you could add the last date modified to the output of that cleaner script?
0
 
Joshua GrantomSystems AdministratorCommented:
Sure,

To add that you just need to add LastWriteTime to the end of the Select-Object like so.

Select-Object Name,Directory,LastWriteTime

This should include it in the CSV
0
 
Junior SofeCommented:
hi,

I am trying to write a PS script that searches for pst files. How can be that be done??
1
 
Dmitry KlimenkoCommented:
I write some script, but need full automatic list of all possible shares on computer (not like users shares, only system: c$, d$, e$, etc). How parse out of this command?
gwmi -class Win32_Share -computer comp1 | ft Name
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now