开发者

Powershell doesn't have access to a network share

开发者 https://www.devze.com 2023-03-28 06:38 出处:网络
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 :

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- t开发者_如何学Che 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?


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


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"


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

精彩评论

暂无评论...
验证码 换一张
取 消