在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