Solved

Powershell script to find files on network computers.

Posted on 2014-09-23
12
6,374 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
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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??
0
 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issues with windows distributed file system 2 34
collection output issue 9 38
How does ADMT SID History work? 1 28
batch file or script 4 27
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

828 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