我使用 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 看不到网络共享?我该如何解决?
最佳答案
听起来像是双跳问题 - http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx - 基本上你正在远程连接到一台机器,然后尝试访问另一台机器。您的 kerberos token 被视为无效,因为在原始和目标之间有一台机器。
您使用的是什么操作系统(源和目标操作系统与 CredSSP 相关)?如果一直是 Windows 2008 或 Windows 7 并且问题是双跳,您可以使用 CredSSP 来避免它 - http://www.ravichaganti.com/blog/?p=1230
关于Powershell 无权访问网络共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7061668/