【问题标题】:Remote Powershell: Mappped Network device shows status unavailable when checked from remote machine远程 Powershell:从远程计算机检查时,映射的网络设备显示状态不可用
【发布时间】:2020-07-01 19:56:54
【问题描述】:

我运行这些 PowerShell 命令的机器是 Ubuntu 18.04 机器,但是当从另一台 Windows 机器运行时,这种行为仍然存在。 我试图通过 Invoke-Command cmdlet 远程执行命令以将文件从 C:\ 复制到映射的网络设备 \\name\share\,但我经常收到此错误:

PS /home/appadmin> Invoke-Command -ComputerName x.x.x.x -ScriptBlock {Copy-Item -Path C:\Directory -Destination \\name\share\ -Recurse -Force} -Credential $cred -Authentication Negotiate
The path is not of a legal form.
+ CategoryInfo          : InvalidArgument: (\\name\share\:String) [Copy-Item], ArgumentException
+ FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName        : x.x.x.x

The handle is invalid.
+ CategoryInfo          : WriteError: (File.vhdx:FileInfo) [Copy-Item], IOException
+ FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName        : x.x.x.x

PS /home/username>

但同样的复制(使用 Copy-Item 命令)从 Windows 主机本身成功。

然后经过进一步调试,得知远程Ubuntu机器上的网络设备状态为Unavailable

PS /home/username> Invoke-Command -ComputerName x.x.x.x -ScriptBlock { net use } -Credential $cred -Authentication Negotiate
New connections will be remembered.
Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Unavailable  Y:        \\name\share         Microsoft Windows Network
The command completed successfully.

PS /home/appadmin>

但是windows主机本身的网络设备状态显示OK

PS C:\Users\Administrator> net use
New connections will be remembered.
Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           Y:        \\name\share         Microsoft Windows Network
The command completed successfully.

PS C:\Users\Administrator>

我已经查看了网络设备的权限,没有问题。 而且这也不是双跳问题。

我应该怎么做才能使远程机器上的网络设备状态为 OK,以便我可以访问映射的网络设备 \name\share? 任何帮助表示赞赏

【问题讨论】:

    标签: windows powershell powershell-remoting winrm mapped-drive


    【解决方案1】:

    您遇到了here 中描述的双跳问题。当您在远程计算机上运行该命令时,它需要凭据才能连接到您的Copy-Item 命令中的-Destination 共享。远程 PowerShell 会话没有您用于通过Invoke-Command 创建第一个远程连接的身份副本,因此您基本上没有-Destination 远程共享的权限。

    记录了多种解决方法here

    【讨论】:

    • 感谢您的意见。我已经尝试过这些方法 CredSSP Authentication、invoke-command 方法 here 和 PSSessionConfiguration 方法 here 中的凭据,但这些方法都不起作用。最后 2 个方法只是挂起,没有任何反应。
    【解决方案2】:

    不知道有没有人遇到过这个问题。但是经过大量搜索后,我给出了完全限定域名 (FQDN) “\\name.name2.local\share\” 而不是“\\name\share\”,最终解决了这个问题。 似乎远程 Powershell 命令很喜欢使用 FQDN,否则它将无法按要求工作。 希望这会有所帮助

    【讨论】:

    • 这看起来是一个难以重现的问题。我猜这与您的特定配置有关。
    • 是的,有可能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    相关资源
    最近更新 更多