Powershell无权访问网络共享

ale*_*lex 3 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

}
}
Run Code Online (Sandbox Code Playgroud)

}

我在计算机1的8台计算机上运行此脚本,使用:

Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1
Run Code Online (Sandbox Code Playgroud)

在第一台计算机上(计算机1 - 我执行脚本的机器)我得到了一个输出但是在计算机上我得到了:

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
Run Code Online (Sandbox Code Playgroud)

为什么Powershell不会看到网络共享?我该如何解决?

Mat*_*att 5

听起来像双跳问题 - 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

  • 我想帮你老兄.您没有提到OS计算机1是什么(在其他8台计算机上运行该命令的计算机).出于兴趣,为什么你这么冒犯有人帮助你呢? (2认同)