Solved

Powershell script to find files on network computers.

Posted on 2014-09-23
12
7,428 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 500 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…

732 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