首页 > 解决方案 > 托管 .NET Core 5 应用程序的 Azure Windows AppService 无法使用 Invoke-Command(“在计算机上找不到服务 WinRM”)

问题描述

我将 .NET Core 5 应用程序部署到 Azure 中的本机 Windows AppSerice。在应用程序内部我运行 Powershell 命令:

Invoke-Command -Computer '{endpoint}' -Scriptblock {{{scriptBody}}} -Credential $credential

endpoint我想在其上运行脚本的运行 Windows 的 Azure VM 的私有 IP 地址在哪里。

AppService 已使用 VNet 集成功能添加到与 Azure VM 相同的 Vnet 中,因此两个“机器”都可以相互访问。

执行时Invoke-Command我得到:

An error has occurred which PowerShell cannot handle. A remote session might have ended.

然后我尝试了Enable-PSRemoting,但我得到了:

Access is denied. To run this cmdlet, start PowerShell with the "Run as administrator" option- 这是可以理解的。我不希望 AppSerice 允许运行管理 cmdlet。

我也试过了Set-Item WSMan:\\localhost\\Client\\TrustedHosts -Value 'endpoint'",我得到:

Service WinRM was not found on computer '.'

WinRm 服务不适用于 Native Windows AppService?这意味着我根本无法使用 AppService 中的远程 Powershell 功能?或者我需要在 Azure 门户中以某种方式安装或启用它?

PS。我尝试从“VM 到 VM”(不是 AppService 到 VM)运行完全相同的Invoke-Command操作,然后它运行良好,以便执行脚本(尽管我需要将 IP 添加到 TrustedHosts)。

标签: azurepowershell.net-coreazure-web-app-service

解决方案


推荐阅读