Powershell – Find a file path on a Server

powershellI just came across this situation recently and I know it comes up every know and then, so I thought I would add it here. I had a situation where I had a list of processes and I needed to find the exact file path of that process on a few servers. So what I did was create a text file that listed the servers. The powershell command takes in that list of servers and scans whatever file path you give it to look on those servers. In my instance it was C:\, but if you want to do a more defined file path just put in c$\windows or whatever path you would like . It then outputs the full file path for that process to a text file. (Keep in mind doing a recursive search on a C:\ takes awhile, so you need to try to limit the path you are searching and your server list, if possible. Here is what the output looks like and  the powershellcode. I hope it helps.

Text file that shows output file path looks something like this:
\\servername\c$\Program Files\Skype for Business Server 2015\Master Replicator Agent\MasterReplicatorAgent.exe

$servers = get-content "C:\scripts\computer.txt" 
ForEach ($server in $servers) { 
Write-Host "Scanning \\$server\c$\" $p = Get-childitem "\\$server\c$\" -recurse | where {$_.name -eq "MasterReplicatorAgent.exe"} 
$p |ft fullname -Wrap|Out-File c:\scripts\replicate.txt -Width 200 -append 

No comments.

Leave a Reply