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?

1
  • Are the two addresses supposed to be different? \\computer1\txtfiles != \\compiuter1\txtfiles
    – JohnL
    Aug 15, 2011 at 11:22

3 Answers 3

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

8
  • as i wrote i have windows 2008 R2 . please read my post . im not using here double hop here !
    – alex
    Aug 15, 2011 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, 2011 at 10:58
  • first line : I got 8 windows 2008 R2 machines . double hop is : ravichaganti.com/blog/?p=1230 read it. but just to be sure i cheked it . and it didnt help .
    – alex
    Aug 15, 2011 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, 2011 at 11:33
  • 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, 2011 at 12:07
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"
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}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.