Powershell 无权访问网络共享

标签 powershell powershell-2.0 powershell-remoting

我使用 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/

相关文章:

file - 如何在PowerShell中将所有Active Directory计算机读入数组?

powershell - 通过 PowerShell 远程处理访问 Azure 云服务 PaaS 实例

powershell - 在 Nano 服务器中设置机器范围的环境变量

c# - PowerShell 2.0 通过 C#,返回值为空?

xml - 需要使用 Xpath 替换 XML 文件中的属性值

powershell - Get-CimInstance win32_networkadapterconfiguration返回Powershell中的MAC和IP地址

regex - 为什么\p{Lu} 匹配小写字母?

powershell - start-job 并行运行脚本

powershell - 使用PowerShell运行我的第三方DLL文件

PowerShell 串联