命令 'Get-AzFunctionApp ' 在 Azure Automation Runbook 中不起作用

The command 'Get-AzFunctionApp ' is not working in Azure Automation Runbook

我创建了一个 Runbook 并添加到下面的 cmdlet

   Get-AzFunctionApp  | Stop-AzFunctionApp

我遇到以下错误

The term 'Get-AzFunctionApp' is not recognized as the name of a cmdlet,

我已经导入了以下所有模块,但没有成功

添加 'Az.Functions' 后出现以下错误

Failed Cannot validate argument on parameter 'SubscriptionId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. (The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.)

此模块中包含 cmdlet Get-AzFunctionApp / Stop-AzFunctionAppAz.Functions

请导入此模块,然后功能相关操作即可。

这是一个例子(请注意为Stop-AzFunctionApp添加-Force参数),它按照我的测试工作:

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

Get-AzFunctionApp -ResourceGroupName xxx | Stop-AzFunctionApp -Force

从您发布的屏幕截图来看,您似乎缺少包含 Get-AzFunctionAppStop-AzFunctionApp cmdlet 的 Az.Functions 模块。

要将 Az.Functions 模块导入您的自动化帐户,请执行以下操作:

  1. 从您的自动化帐户,在 共享资源、select 模块.
  2. Select 浏览图库.
  3. 在搜索栏中,输入模块名称(Az.Functions)。
  4. 在“PowerShell 模块”页面上,select导入 将模块导入您的自动化帐户。

您也可以通过PowerShell Gallery. Choose the Azure Automation tab and select Deploy to Azure Automation from here: Az.Functions导入模块。