My script should look for a file in a computer list (txt) and return true if the file exists and false if it doesn't.
The problem is, it's returning "False" even though the file DOES exist.
$computers = Get-Content -Path C:\temp\SvcHosts\PSKILL_SvcHosts_Workstations.txt
foreach ($comp in $computers)
{
Test-Path \\$comp\c$\Windows\myfolder\myapp.exe
}
When I run Test-Path \\COMPUTERNAME\c$\Windows\myfolder\myapp.exe alone it returns true as it should.
When I run from the txt list, returns false when it shouldn't.
Any ideas?
This sounds strange, but I just ran my script (without change it) in another machine and it worked as expected. The main difference between the two machines I tested the script is the version of PowerShell ISE.
Machine 1 ISE Version: 3.0 Test-Path returns false even if the file exists
Machine 2: ISE Version:2.0 Test-Path works fine.
Not sure if these versions have difference betweeen them about access or something. I have the impression that it returned false in Machine 1 because the script couldn't reach the computer (I was running it under admin privileges anyway).
I know it doesn't make much sense...but anyway, case closed. Many thanks to everyone that helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With