Get the list of server names which does not have file on remote servers

I have a script, which will provide me the the server names, If file exists. I am stuck up with small issue. Looking for the output: If the file is present, ignore. If the file is not present, get the output with server name. Can someone please help on this? Below is my script:

function check-remotefile {
 
    PROCESS {
 
                $file = "\\$_\c$\Program Files (x86)\test\access\tomcatupgrade.txt"
 
                if (test-path $file)
 
                {
 
                echo "$_ file tomcatupgrade.txt exists"
 
                }
 
            }
 
}
 
Get-Content  C:\Users\venkatak\Desktop\Scripts\Tomcat_Check\Computers.txt | check-remotefile

-Kalyan

If you like your function to take pipeline input you will have to add a param block and tell it to do so. :wink: Start with reading the help for it:

Get-Help about_Functions_Advanced_Parameters

I think you just need an ELSE statement

function check-remotefile {
 
    PROCESS {
 
                $file = "\\$_\c$\Program Files (x86)\test\access\tomcatupgrade.txt"
 
                if (test-path $file)
 
                {
 
                echo "$_ file tomcatupgrade.txt exists"
 
                }
                else 
                {
                    Write-output "$_ file does NOT exist"'
                }
 
            }
 
}

BTW: Echo is just an alias for Write-Output.

This function is not typical, it should work for pipeline input. Take the advice of Olaf and use parameters, it will make it easier to read and debug in the future. Plus it will work better too.

one line:

"localhost","127.0.0.1"  | % {if(!(test-path "c:\temp\test.txt")){Write-Output "$_ File not found"}}