gpt4 book ai didi

azure - 如何使用 Azure 自动化删除应用服务

转载 作者:行者123 更新时间:2023-12-03 05:36:47 25 4
gpt4 key购买 nike

以下代码通过 Azure Cloud Shell 运行良好(完成,应用服务按预期删除)。

Remove-AzWebApp -ResourceGroupName "ResourceGroup1" -Name "AppService1" -Force

它也在我的 Runbook 工作流程中顺利完成,但应用服务仍保持运行状态。这感觉像是权限问题,但我尝试在订阅级别添加所有者角色,但没有成功。

关于如何让 AzureRunAsConnection 帐户实现此功能,有什么想法/提示吗?

最佳答案

This feels like a permissions problem, but I've tried adding the Owner role at the subscription level without success.

这不是权限问题,当您与 RunAsAccount 一起创建自动化帐户时,它会将与 RunAsAccount 相关的服务主体作为 Contributor 角色添加到订阅中,这足以删除网络应用程序。

如果您使用的是PowerShell Workflow Runbook,请尝试下面的示例,它对我有用。 (首先,确保您已在自动化帐户 -> 模块 中安装了 Az.AccountsAz.Websites 模块。)

workflow testrun3
{
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName

Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}

Remove-AzWebApp -ResourceGroupName "<group-name>" -Name "joywebapp1234" -Force
}

enter image description here

在门户中检查结果:

enter image description here

关于azure - 如何使用 Azure 自动化删除应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61844390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com