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]术语'更新-AceanRmEventGridSubscription'不被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
[编辑]
任务:Azure PowerShell 描述:在Azure环境中运行PowerShell脚本 版本:2.0.11 作者:微软公司
[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 [命令]&安培; ' d:\ A \ R1 \ A \工具\脚本\新EventGridSubscription.ps1' -ResourceGroupName -FunctionApps -EventGridTopicName *
[error]术语'更新-AceanRmEventGridSubscription'不被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 [section]整理:Azure PowerShell脚本:New-EventGridSubscription
答案 0 :(得分:1)
请参阅以下步骤:
脚本:
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
Specify other version
;首选Azure PowerShell Versioin:6.0.1
)相关主题:Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services)