目标机器上的 powershell 导致 "PSSession could not be created for Machine:'XXX:5986"

powershell on target machine causes "PSSession could not be created for Machine:'XXX:5986"

我尝试使用发布管道并设置任务“运行 目标机器上的 powershell”

错误信息如下:

##[error]Unable to create pssession. Error: 'Connecting to remote server XXX failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.'

##[error]The remote session query failed for XXX with the following error message: The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". 

##[error]PSSession could not be created for Machine:'XXX:5986'

我的虚拟机在 Azure 上,我已经在 'internet' 设置中打开了 598685 端口。 我发现一些文章谈论“远程管理”,但是,我不确定如何在我的 VM 上设置它。

https://docs.microsoft.com/en-us/windows/win32/winrm/portal https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/winrmsecurity?view=powershell-7.2

也许我需要对 运行ning 管道实例(代理池)进行一些设置? https://developercommunity.visualstudio.com/t/with-powershell-on-target-machines-task-cant-able/635225

欢迎任何建议。

更新-1

@wade-zhou-msft 的建议似乎不起作用。不过谢谢!

Updata-2 更改网络设置,不再有错误。 但是情况还是一样...

此外,我的 'copy file to remote machine' 任务运行良好。

更新-3 我发现有关“如何从 Linux 远程 运行 powershell 命令”的文章 https://adamtheautomator.com/psremoting-linux/ 它表明需要进行一些设置。也许我需要设置实例 运行宁我的 CD 作业?

任务“运行 目标机器上的 powershell”将启动一个 Enter-PSSession 会话,从 your agent machinetarget VM

根据错误消息,在您的目标 VM 上,请 运行 winrm quickconfig 配置服务,运行 winrm set winrm/config/client '@{TrustedHosts="*"}' 信任主机。

如果使用HTTPS,则需要在防火墙中打开5986端口并安装self-signed证书。

如果您从 Azure 门户创建经典虚拟机,则虚拟机已通过 HTTPS 为 WinRM 设置,默认端口 5986 已在防火墙中打开,self-signed 证书安装在machine.These 无需进一步配置即可访问虚拟机。详情请参考task perquisite

或者您可以使用 self-hosted 代理,任务使用 http 端口 5985。