You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Automation无法停止Azure Function App的技术求助

Troubleshooting Azure Automation Runbook Error When Stopping Azure Function App

Let me walk through the common issues that might be causing your script to fail, along with actionable fixes:

1. Module Conflicts & Missing Az.Functions Module

Your script uses Add-AzureRmAccount (from the legacy AzureRM module) alongside Stop-AzFunctionApp (from the modern Az module) – these two module sets don't play well together. Plus, Azure Automation doesn't include Az.Functions by default, so you need to make sure it's properly imported into your Automation account.

Fix Steps:

  • Go to your Azure Automation account → Modules → Check if Az.Functions is listed. If not, click Browse gallery, search for Az.Functions, and import it. Also ensure core Az modules like Az.Accounts are up-to-date (outdated modules can cause compatibility issues).
  • Replace the legacy login command with the Az module equivalent in your script:
$connectionName = "AzureRunAsConnection"
try {
    # Get the connection "AzureRunAsConnection"
    $servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
    "Logging in to Azure using Az module..."
    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
    }
}

# Safeguard to ensure Az.Functions is loaded
Import-Module Az.Functions -Force

Stop-AzFunctionApp -Name myapp202110 -ResourceGroupName AppRG

2. Insufficient Permissions for RunAs Account

The RunAs service principal might not have the right permissions to stop your Function App.

Fix Steps:

  • Navigate to your Function App → Access control (IAM) → Add role assignment.
  • Assign the Website Contributor role (or a custom role with Microsoft.Web/sites/stop/action permission) to the RunAs service principal (search for its application ID or name).

3. Verify Resource Details

Double-check that:

  • The Function App name myapp202110 matches exactly what's in Azure (case-insensitive, but typos happen!)
  • The resource group name AppRG is correct and exists in the same subscription your RunAs account has access to.

4. Check Detailed Error Logs

If the issue persists, go to your Runbook's Execution history, select the failed run, and expand the error details. This will tell you exactly what's wrong – whether it's a module load failure, permission error, or resource not found issue.

内容的提问来源于stack exchange,提问作者Kamal Rathnayake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 18:07:34