【问题标题】:Powershell doesn't have access to a network sharePowershell 无权访问网络共享
【发布时间】:2018-03-20 00:23:42
【问题描述】:

我使用 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 看不到网络共享?我该如何解决?

【问题讨论】:

  • 这两个地址应该不同吗? \\computer1\txtfiles != \\compiuter1\txtfiles

标签: powershell powershell-2.0 powershell-remoting


【解决方案1】:

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

【讨论】:

  • 正如我所写,我有 Windows 2008 R2。请阅读我的帖子。我没有在这里使用双跳!
  • 对不起,你确实写了,我认为你需要配置 CredSSP。需要明确的是,Double Hop 不是你使用的东西,你在这里写的每一件事都表明这是问题所在(尤其是 Manojlds 给你的代码不起作用。
  • 第一行:我有 8 台 windows 2008 R2 机器。双跳是:ravichaganti.com/blog/?p=1230 阅读。但只是为了确保我检查了它。它没有帮助。
  • 我正在努力帮助你,伙计。您没有提到 OS 计算机 1 是什么(您在其他 8 台机器上运行命令的计算机)。出于兴趣,你为什么对帮助你的人如此冒犯?
  • 很公平。我很想知道解决方案是什么,所以我会回来查看。祝您好运解决您的问题并学习一些礼仪。
【解决方案2】:

如果不是访问控制的问题,那么考虑一下我在通过服务器复制文件时遇到的类似问题:

找不到路径“\\computer1\d$\path”,因为它不存在。

在文件名前添加Microsoft.PowerShell.Core\FileSystem::后生效:

copy-item "Microsoft.PowerShell.Core\FileSystem::\\computer1\d$\path\installer.msi" "Microsoft.PowerShell.Core\FileSystem::\\computer2\d$\path\installer.msi"

【讨论】:

    【解决方案3】:

    编辑:

    我能够重现此问题,这可能是双跳问题。我按照这里的说明解决了:

    http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

    (或马特给出的链接)


    确保 computer2 和其他计算机能够看到该共享。如果其他机器一开始看不到共享,Powershell 什么也做不了。

    做一个简单的检查:

    Invoke-Command -computer computer2 -script {dir \\computer1\txtfiles}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      相关资源
      最近更新 更多