Powershell 无法访问网络共享
我使用 powershell 检查我的计算机上的端口是否打开。我有 8 台 Windows 2008 R2 机器,我运行以下脚本:
$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
}
}
}
并且我使用以下命令在计算机 1 的 8 台计算机上运行此脚本:
Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1
在第一台计算机(计算机 1-我执行脚本的计算机)上,我得到了输出,但在我得到的计算机2:
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
为什么Powershell看不到网络共享?我该如何修复它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来像是双跳问题 - http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx - 基本上,您正在远程连接到一台计算机,然后尝试访问另一台计算机。您的 kerberos 令牌被视为无效,因为原始令牌和目标令牌之间有一台机器。
您使用什么操作系统(源操作系统和目标操作系统与 CredSSP 相关)?如果一直是 Windows 2008 或 Windows 7 并且问题是双跳,您可以使用 CredSSP 来避免它 - http://www.ravichaganti.com/blog/?p=1230
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
如果不是访问控制问题,请考虑我在通过服务器复制文件时遇到的类似问题并出现此错误:
它在文件名前面添加
Microsoft.PowerShell.Core\FileSystem::
后即可工作:If it's not a problem with access control, then consider a similar problem I faced when copying files over servers with this error:
It works after adding
Microsoft.PowerShell.Core\FileSystem::
in front of file name:编辑:
我能够重现这个问题,这可能是双跳问题。我按照此处的说明解决了它:
http:// blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx
(或马特给出的链接)
确保computer2 和其他计算机能够看到该共享。如果其他计算机一开始就无法看到共享,则 Powershell 将无法执行任何操作。
对于简单的检查,请执行以下操作:
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: