Networknet archive Blog

PowerShell: Check remote computers for a specific file

Originally published Last updated 6 comments

By Ivan Versluis

I want to check whether install.exe exists on a list of remote computers and display each computer name where the file is found.

The PowerShell script below defines a function for the session and pipes computer names from a text file to it.

Create C:\Scripts\Active_Computers.txt and add the computer names.

PowerShell19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
function check-remotefile {

    PROCESS {

                $file = "\\$_\c$\install.exe"

                if (test-path $file)

                {

                echo "$_ file install.exe exists"

                }

            }

}

Get-Content  C:\Scripts\Active_Computers.txt | check-remotefile

6 comments

Comments from the original WordPress site, kept read-only.

  1. Johan

    How would one make this a vbscript instead of powershell?
    Need a vbscript that check a list of computernames, if there's a specific file under c:\program files\myapp

  2. Tony

    Hi Ivan

    Nice script! How could I add the functionality to search for specific multiple files on a remote computer?

  3. Tony

    Nice Script!
    How can I add functionality to get the LastWriteTime, DateModified, CreationDate of the remote file?

  4. Maelito

    Great script and works beautifully

    I have added the line just to look good

    Write-Host "$_" -Foregroundcolor Green

    Maelito