Powershell cant access to a network share

by Aug 15, 2011

I use powershell to check if the ports are opened on my computers. I got 8 windows 2008 R2 machines and I run the following script :

$localhost = get-content env:computername

foreach($port in get-content "\computer1txtfilesports.txt")
{

foreach ($hostname in get-content "\compiuter1txtfilesservers.txt")
    {
    try {
        $sock = new-object System.Net.Sockets.Socket -ArgumentList $([System.Net.Sockets.AddressFamily]::InterNetwork),$([System.Net.Sockets.SocketType]::Stream),$([System.Net.Sockets.ProtocolType]::Tcp)
    $sock.Connect($hostname,$Port)
    $output = $localhost+","+$hostname+","+$port+","+$sock.Connected
    $output
    $sock.Close()
}
catch {

    $output = $localhost+","+$hostname+","+$port+","+$sock.Connected
    $output

}
}

}

And I run this script on the 8 computer from computer1 using :

Invoke-Command -ComputerName computer1,computer2 -FilePath F:scriptsport-test.ps1

On the first computer (computer1- the machine that I execute the script from ) I got an output but on the computer2 I got :

Cannot find path '\computer1txtfiles' because it does not exist. 

    + CategoryInfo          : ObjectNotFound: (\computer1txt
   files:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Why isn't Powershell seeing network share? How can I fix it?