Networknet archive Blog

PowerShell: Check remote computers for a specific file

Originally published Last updated 6 comments

This PowerShell script checks for a file on computers listed in a text file. It defines a function for the session and pipes the computer names from the file to that function.

In this example, I will check whether install.exe exists on each remote system and display the computer name when the file is found.

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