在远程 Windows 计算机上通过 MacOs Visual Studio Code 运行 Powershell 脚本会抛出 MI_RESULT_FAILED

Ric*_*rdo 6 windows macos powershell ntlm visual-studio-code

我正在尝试通过 Visual Studio Code 在 MacOS (Monterey M1) 上运行和调试 Powershell 脚本(专为在远程 Windows PC 上运行而定制)。

\n

苹果

\n
Name Value\n---- -----\nPSVersion 7.2.1\nPSEdition Core\nGitCommitId 7.2.1\nOS Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.6\xe2\x80\xa6\nPlatform Unix\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0\xe2\x80\xa6}\nPSRemotingProtocolVersion 2.3\nSerializationVersion 1.1.0.1\nWSManStackVersion 3.0\n
Run Code Online (Sandbox Code Playgroud)\n

个人电脑

\n
 Name                           Value\n----                           -----\nPSVersion                      7.2.1\nPSEdition                      Core\nGitCommitId                    7.2.1\nOS                             Microsoft Windows 10.0.19043\nPlatform                       Win32NT\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0\xe2\x80\xa6}       \nPSRemotingProtocolVersion      2.3\nSerializationVersion           1.1.0.1\nWSManStackVersion              3.0\n
Run Code Online (Sandbox Code Playgroud)\n

在 Mac 上,我已经安装PSWSMan并遵循这篇文章https://petri.com/how-to-run-code-remotely-in-visual-studio-code我尝试使用以下命令启动远程会话:

\n
Enter-PSSession -ComputerName \'192.168.1.185\' -Credential xxx\n
Run Code Online (Sandbox Code Playgroud)\n

输入密码后系统立即抛出此错误:

\n
Enter-PSSession: Connecting to remote server 192.168.1.185 failed with the following error message : MI_RESULT_FAILED For more information, see the about_Remote_Troubleshooting Help topic.\n
Run Code Online (Sandbox Code Playgroud)\n

这可能是由于 NTLM 不兼容造成的:https://github.com/dotnet/runtime/issues/887

\n

有人成功运行这个场景吗?

\n

Eme*_*ldo 1

要解决 MI_RESULT_FAILED 问题,请尝试使用凭据的完整 UPN。

\n

我们的系统位于域中(我的基于 M1 的 Mac 不在域中)。我们公司内部 AD 域的格式如下:(DOMAIN.LOCAL与 domain.com 或我们用于电子邮件和 Azure 登录的备用域 emaildomain.com 相反)。我能够使用以下命令成功远程访问名为 MYPC01 的基于 Windows 的计算机:

\n
Enter-PSSession -ComputerName MYPC01 -Credential username@domain.local\n
Run Code Online (Sandbox Code Playgroud)\n

下面的屏幕截图是我从 Mac 成功连接到域控制器的情况:

\n

从 Mac 到 PC 成功连接 PowerShell 的屏幕截图

\n

键入exit退出会话并返回到 Mac 终端中的本地 PS 会话。

\n
\n

作为参考,下面是我的 Mac PowerShell 安装的输出:

\n
$PSVersionTable\n\nName                           Value\n----                           -----\nPSVersion                      7.3.4\nPSEdition                      Core\nGitCommitId                    7.3.4\nOS                             Darwin 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:41 PST 2023; root:xnu-8796.101.5~3/\xe2\x80\xa6\nPlatform                       Unix\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0\xe2\x80\xa6}\nPSRemotingProtocolVersion      2.3\nSerializationVersion           1.1.0.1\nWSManStackVersion              3.0\n
Run Code Online (Sandbox Code Playgroud)\n
\n

注意:您必须已安装 WSMan在 macOS 上更新 PowerShell 后可能需要重新安装

\n
pwsh -Command \'Install-Module -Name PSWSMan\'\nsudo pwsh -Command \'Install-WSMan\'\n
Run Code Online (Sandbox Code Playgroud)\n