【问题标题】:Access is denied when trying to connect the machine remotely using Powershell command尝试使用 Powershell 命令远程连接机器时访问被拒绝
【发布时间】: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对象

标签: powershell remote-access


【解决方案1】:

除了问题中提到的步骤之外,完成的附加设置是 需要连接的远程计算机上的“winrm quickconfig”。

然后执行

Enter-PSSession –ComputerName [MachineName] -EnableNetworkAccess -Credential [username] -Authentication Default

会话开始,然后我能够执行并获取远程机器的详细信息,无论域相同还是不同

【讨论】:

    猜你喜欢
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多