【问题标题】:Update-AzureRmEventGridSubscription in VSTS is not recognized as the name of a cmdletVSTS 中的 Update-AzureRmEventGridSubscription 未被识别为 cmdlet 的名称
【发布时间】:2018-10-30 18:25:48
【问题描述】:

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、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

[编辑]

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

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

帮助:More Information

[command]Import-Module -Name C:\Modules\AzureRm_5.1.1\AzureRM\5.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

【问题讨论】:

  • Import-Module AzureRM
  • 尝试使用最新版本的 Azure RM 任务和 VS 2017 托管代理(如果您使用托管)。如果您使用自己的代理,请为其安装适当的 AzureRM 模块
  • [command]Import-Module -Name C:\Modules\AzureRm_5.1.1\AzureRM\5.1.1\AzureRM.psd1 -Global

标签: powershell azure-devops azure-eventgrid


【解决方案1】:

参考以下步骤:

  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

相关话题:Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services)

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多