2

I use PowerShell to check if any ports are open on my computers. I have eight Windows Server 2008 R2 machines and run the following script:

$localhost = get-content env:computername

foreach($port in get-content "\\computer1\txtfiles\ports.txt")
{

    foreach ($hostname in get-content "\\compiuter1\txtfiles\servers.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
        }
    }
}

I run this script on the eight computers from computer1 using:

Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1

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

Cannot find path '\\computer1\txtfiles' because it does not exist.
+ CategoryInfo          : ObjectNotFound: (\\computer1\txt
files:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLo
cationCommand

Why doesn't PowerShell see the network share? How can I fix it?

4
  • can you manually type in \\computer2\txtfiles in another computer's run box and reach it?
    – Keltari
    Aug 15, 2011 at 4:18
  • yes i can go to this share
    – alex
    Aug 15, 2011 at 5:12
  • My guess is that on each machine, the command is trying to run on both c1 & c2... and c2 doesn't know what c1 is... try modifying the script so that it runs in a loop... foreach $PcName in @ComputerList { Invoke-Command -ComputerName $PcName ... }. Okay, that's just pseudo-code, but the idea is to only pass one computer name at a time to the command. Aug 15, 2011 at 6:31
  • if i run from computer1: invoke-command -computername cumputer2 ... i get the same error message
    – alex
    Aug 15, 2011 at 8:11

1 Answer 1

3

My best guess is that the cause of this is a failed Kerberos multi-hop.

I guess what happening here is that the computer2 cannot access computer1 because it tries to access the share of computer1 with no login (Null session) or the computer credentials of computer2 (DOMAIN\Computer2$). Since this login does not have any rights, reading the text file fails.

Computer1 -> Script runs under your account -> Your account is used to access Computer1 -> Runs fine

Computer1 -> Run Script on Computer2 -> PowerShell connects to WinRM using your account -> You have access rights, so WinRM accepts the call -> PowerShell send the scripts to WinRM -> WinRM starts the script under its account (Computer2$) -> Computer1 sees an incoming request to \txtfiles from the account "Computer2$" -> This account has no rights so the access is denied -> Error

As a first shot, I would try to give the user Everyone read access to the share \txtfiles. If this doesn't help, try to pass your login with -credential domain\YourName to Invoke-Command.

I guess the root cause is Kerberos related since this document says WinRM is able to use delegation of user logins.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .