【发布时间】:2020-11-16 13:01:22
【问题描述】:
我正在寻找用于连接远程机器并在该会话中进一步执行命令的 powershell 脚本/命令。
浏览了 Stackoverflow 上的各种博客和类似帖子,发现我们需要启动 PS-Session 来连接远程机器。但解决方案没有成功。所以,想用我尝试的场景提出一个新问题。
为此,我在两台机器上都启用了 PSRemoting,并在受信任的主机列表中添加了远程机器 IPAddress 和机器名称。执行以下命令时仍然出现 Access is Denied 错误。
Enter-PSSession –ComputerName [Machinename] -Credential username
然后我发现两台机器的域名不同。但是为此,如果我们在受信任的主机中添加机器名称,请清除缓存并重置 psconfiguration 它应该可以工作。
但是,它仍然无法正常工作并抛出相同的错误
Enter-PSSession : Connecting to remote server [MachineName] failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At C:\PathOfPowerScript\servertest.ps1:11 char:7
Enter-PSSession –ComputerName [MachineName] -EnableNetworkAccess -C ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidArgument: ([MachineName]:String) [Enter-PSSession], PSRemotingTransportException
FullyQualifiedErrorId : CreateRemoteRunspaceFailed
任何有工作解决方案或建议继续前进的人。
【问题讨论】:
-
As the docs 状态:Credential:键入用户名,例如 User01 或 Domain01\User01,或输入由 Get-Credential cmdlet 生成的 PSCredential 对象。如果您键入用户名,系统会提示您输入密码。。所以对
username使用真正的PSCredential对象