首页 > 解决方案 > VSTS 中的 Update-AzureRmEventGridSubscription 未被识别为 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 部署的一部分运行它会引发异常:

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

[编辑]

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

任务:Azure PowerShell 描述:在 Azure 环境中运行 PowerShell 脚本版本:2.0.11 作者:Microsoft Corporation

帮助:更多信息

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

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

标签: powershellazure-devopsazure-eventgrid

解决方案


请参考以下步骤:

  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:)

相关主题:在 Hosted 2017 Agent 上升级 AzureRM Powershell(VSTS - Visual Studio Team Services)


推荐阅读