3

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 "\\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

}
}

}

And I run this script on the 8 computer 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 got an output but on the computer2 I got :

Cannot find path '\\computer1\txtfiles' because it does not exist. 

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

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

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
alex
  • 916
  • 4
  • 12
  • 26
  • Are the two addresses supposed to be different? `\\computer1\txtfiles` != `\\compiuter1\txtfiles` – JohnL Aug 15 '11 at 11:22

3 Answers3

5

Sounds like the double hop issue - http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx - basically you are remoting to one machine and then trying to access another machine. your kerberos token is seen as invalid as there's a machine in between the original and the destination.

What OS are you using (the source and the destination OS is relevant for CredSSP)? If it is Windows 2008 or Windows 7 all the way through and the issue is double hop you may be able to us CredSSP to avoid it - http://www.ravichaganti.com/blog/?p=1230

Matt
  • 1,931
  • 12
  • 20
  • as i wrote i have windows 2008 R2 . please read my post . im not using here double hop here ! – alex Aug 15 '11 at 10:10
  • sorry you did write that, I think you'll need to configure CredSSP. To be clear Double Hop isn't something you use and every thing you've written here points to this being the problem (esp as the code Manojlds gave you doesn't work. – Matt Aug 15 '11 at 10:58
  • first line : I got 8 windows 2008 R2 machines . double hop is : http://www.ravichaganti.com/blog/?p=1230 read it. but just to be sure i cheked it . and it didnt help . – alex Aug 15 '11 at 11:27
  • 2
    I am trying to help you dude. You don't mention what OS computer 1 is (the computer you run the command on the other 8 machines). Out of interest why are you so offensive to someone helping you? – Matt Aug 15 '11 at 11:33
  • out of interest can you RDP onto the boxes and run this command "dir \\computer1\txtfiles" – Matt Aug 15 '11 at 11:34
  • 1
    fair enough. I'm interested to see what the resolution is so I'll check back. Good luck resolving your issue and learning some manners. – Matt Aug 15 '11 at 12:07
  • This is a double hop issue. -> Computer2 (via Invoke-Command) -> \\computer1\... You will get a "not found" error since it can't pass your credentials along. The tell tale sign is that Computer1 works and Computer2 does not. – JasonMArcher Aug 15 '11 at 17:46
  • +1 - does look like a double hop issue and was able to reproduce and fix it. – manojlds Aug 15 '11 at 18:27
4

If it's not a problem with access control, then consider a similar problem I faced when copying files over servers with this error:

Cannot find path '\\computer1\d$\path' because it does not exist.

It works after adding Microsoft.PowerShell.Core\FileSystem:: in front of file name:

copy-item "Microsoft.PowerShell.Core\FileSystem::\\computer1\d$\path\installer.msi" "Microsoft.PowerShell.Core\FileSystem::\\computer2\d$\path\installer.msi"
George
  • 6,006
  • 6
  • 48
  • 68
1

Edit:

I was able to reproduce this and it can be the double-hop issue. I solved it as per the instructions here:

http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

( or the link that Matt had given)


Make sure computer2 and other computers are able to see that share. If the other machines are not able to see the share in the first place, Powershell cannot do anything.

For a simple check do:

Invoke-Command -computer computer2 -script {dir \\computer1\txtfiles}
manojlds
  • 290,304
  • 63
  • 469
  • 417