首页 文章

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

提问于
浏览
0

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

$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]术语“Update-AzureRmEventGridSubscription”未被识别为cmdlet,函数,脚本文件或可操作程序的名称 . 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试 .

[编辑]

[section]开始: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 [command] Select-AzureRMSubscription -SubscriptionId** -TenantId **** [command]& 'D:\a\r1\a\Tools\scripts\New-EventGridSubscription.ps1' -ResourceGroupName -FunctionApps **** **-EventGridTopicName ***

[error]术语“Update-AzureRmEventGridSubscription”未被识别为cmdlet,函数,脚本文件或可操作程序的名称 . 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试 . [section]完成:Azure PowerShell脚本:New-EventGridSubscription

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
    
    • 编辑Azure PowerShell任务(Azure PowerShell版本: Specify other version ;首选Azure PowerShell Versioin: 6.0.1

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

相关问题