VSTS 中的 Update-AzureRmEventGridSubscription 未被识别为 cmdlet 的名称

Update-AzureRmEventGridSubscription in VSTS is not recognized as the name of a cmdlet

VSTS deploy 期间,我正在调用任务 Azure PowerShell(首选 Azure PowerShell 版本 5.1.1),我正在检查事件网格订阅和我正在添加或更新:

$subscriptions =  Get-AzureRmEventGridSubscription -ResourceGroupName $ResourceGroupName -TopicName $EventGridTopicName  | WHERE EventSubscriptionName -eq $Subscription.Name
if (!$subscriptions) 
{
    Write-Host 'Add new subscription'
    New-AzureRmEventGridSubscription -ResourceGroup $ResourceGroupName -TopicName $EventGridTopicName -Endpoint $Subscription.endpoint -EventSubscriptionName $Subscription.Name
    Write-Host 'New subscription added'
}
else {
    Write-Host 'Update endpoint'
    Update-AzureRmEventGridSubscription -ResourceGroup $resourceGroupName -TopicName $eventGridTopicName -Endpoint $endpoint -EventSubscriptionName $eventGridSubscriptionName
    Write-Host 'Subscription endpoint updated'
}

运行从本地机器运行这段代码工作正常。 运行将其作为 VSTS 部署的一部分抛出异常:

[error]The term 'Update-AzureRmEventGridSubscription' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

[编辑]

[部分]开始:Azure PowerShell 脚本:New-EventGridSubscription

任务:Azure PowerShell 描述:运行 Azure 环境中的 PowerShell 脚本 版本:2.0.11 作者:微软公司

帮助:More Information

[command]Import-Module -Name C:\Modules\AzureRm_5.1.1\AzureRM.1.1\AzureRM.psd1 -Global [命令]Add-AzureRMAccount -ServicePrincipal -Tenant * -Credential System.Management.Automation.PSCredential -Environment AzureCloud [命令] Select-AzureRMSubscription -SubscriptionId -TenantId [command]& 'D:\a\r1\a\Tools\scripts\New-EventGridSubscription.ps1' -ResourceGroupName -FunctionApps -EventGridTopicName *

[错误]术语 'Update-AzureRmEventGridSubscription' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 [部分]完成:Azure PowerShell 脚本:New-EventGridSubscription

参考这些步骤:

  1. 添加 PowerShell 任务

脚本:

Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"}  | Select Name, Version
Install-Module -Name AzureRM -RequiredVersion 6.0.1 -Force -Scope CurrentUser -AllowClobber
Import-Module AzureRM -Force -Verbose -Scope Local 
Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"}  | Select Name, Version
  1. 编辑您的 Azure PowerShell 任务(Azure PowerShell 版本:Specify other version;首选 Azure PowerShell 版本:6.0.1

相关主题: