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
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.