?
Solved

Powershell script to find files on network computers.

Posted on 2014-09-23
12
Medium Priority
?
8,959 Views
1 Endorsement
Last Modified: 2016-11-01
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
Comment
Question by:mobanker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40339166
are you just searching in shares or or you trying to search the entire hard drive of every computer on the network?
0
 

Author Comment

by:mobanker
ID: 40339173
Searching the entire drive.  Drives C: and D: should cover everything.

Thank you!
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 2000 total points
ID: 40339298
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mobanker
ID: 40339314
A thing a beauty!  Thank you for your help Joshua.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40339344
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
 

Author Comment

by:mobanker
ID: 40340060
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
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40340111
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
 

Author Comment

by:mobanker
ID: 40340125
It is running!  Have a great day and thank you very much.
0
 

Expert Comment

by:Member_2_7971328
ID: 41753011
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
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 41753291
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
 

Expert Comment

by:Junior Sofe
ID: 41837787
hi,

I am trying to write a PS script that searches for pst files. How can be that be done??
1
 

Expert Comment

by:Dmitry Klimenko
ID: 41868516
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question