我正在使用内置的“部署 Azure 应用服务”步骤部署应用服务。它因以下错误而失败:
术语“Remove-WebConfigurationLock”未被识别为名称 cmdlet、函数、脚本文件或可操作程序的组成。
我有另一个正在运行的项目,日志显示它使用不同版本的 PowerShell。我很确定问题是我无法通过此步骤选择 PowerShell Core。我不知道为什么另一个人用它。
使用内置的“部署 Azure 应用服务”步骤时,我没有允许我使用 PowerShell Core 的选项。
当我运行基本的 PowerShell 脚本步骤时,我可以选择使用 PowerShell Core。我使用下面的“配置功能”按钮添加它。
“部署 Azure 应用服务”步骤中没有“配置功能”按钮。
如何执行“部署 Azure 应用服务”步骤来使用 PowerShell Core?
更新:
我创建的两个项目正在使用 PowerShell 核心 (PS7),但我没有做任何事情来导致这种情况(我可以找到)。
我的最新项目正在使用 PowserShell Desktop (PS5)。
使用 PS5 的新项目在之前的步骤中使用 PS7。
更新:-
我尝试使用
Default Worker pool
,并将 Powershell 设置为 Windows 桌面和 PS-version is also 5.1
。我的下面的 Powershell 脚本成功运行。
# Display PowerShell version
$PSVersionTable.PSVersion.ToString()
# Install the IIS Web Role
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# Import the WebAdministration module
Import-Module WebAdministration
# Specify the PSPath and Filter
$PSPath = 'IIS:\Sites\Default Web Site'
$Filter = 'system.webServer/security/authentication/anonymousAuthentication'
# Remove the Web configuration lock
Remove-WebConfigurationLock -PSPath $PSPath -Filter $Filter
# Restart IIS to apply changes
Restart-WebAppPool -Name 'DefaultAppPool'
iisreset /restart
输出:- Powershell 版本 - 5.1
工作池 - 默认工作池 PowerShell 版 - Windows Powershell(桌面)
AFAIK,
Remove-WebConfigurationLock
是 Web 管理模块 的一部分,并且 Web 管理模块仅适用于安装了 IIS Web 角色的 Windows Server 2022。请参阅此 SO 线程答案 1 和 SO 线程答案 2 相同。
此外,根据 Octopus 配置设置,Powershell Core 仅在“非 Windows 计算机”中受支持,因此您需要检查正在使用哪个工作池来运行您的版本。在我这边选择 Powershell Core 和 Ubuntu Worker 后,Remove-WebConfigurationLock
也失败了,如下所示:-
作为解决方法,您可以使用 Windows 2022 服务器映像创建动态工作池,如下所示,并在动态工作池中安装 IIS Web 角色。然后运行 Powershell 命令。请参阅以下:-
然后在 Powershell 任务中选择上述工作池并运行以下命令以首先安装 IIS Web 角色,然后运行您的命令:-
在内联源代码中添加以下代码:-
# Install the IIS Web Role
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
# Import the WebAdministration module
Import-Module WebAdministration
# Specify the PSPath and Filter
$PSPath = 'IIS:\Sites\Default Web Site'
$Filter = 'system.webServer/security/authentication/anonymousAuthentication'
# Remove the Web configuration lock
Remove-WebConfigurationLock -PSPath $PSPath -Filter $Filter
# Restart IIS to apply changes
Restart-WebAppPool -Name 'DefaultAppPool'
iisreset /restart
上面的代码也适用于 Windows-Desktop Powershell 以及上面的 Powershell Core。 现在,运行此命令后,您可以在部署 Azure Web 应用程序(Web 部署)中使用 Windows Server Core 2022 工作池来部署包。但据这位官员透露 有关部署 Azure Web 应用程序任务的 octopus 文档。该任务不包含任何配置 Powershell 版本的设置。
Azure Web 应用程序 |文档和支持 (octopus.com)。您需要向八达通提出支持请求才能获得该功能。另外,在创建 Web 应用程序包时,您可以将上述方法与 WindowsAdministration 包结合使用,然后在部署 Azure Web 应用程序步骤中使用它。