Powershell 如何在VSTS任务中使用最新的AzureRM

Powershell 如何在VSTS任务中使用最新的AzureRM,powershell,azure,azure-devops,Powershell,Azure,Azure Devops,我想执行命令删除远程azure资源组上的主题或队列。其中一个命令是“Get-AzureRmServiceBusQueue” 我在VST的托管代理中使用Azure Powershell任务(使用Azure资源管理器)。此任务正在使用Azure Powershell 2.0.1 当我执行释放时,代理返回此故障: "[error]The term 'Get-AzureRmServiceBusQueue' is not recognized as the name of a cmdlet, functi

我想执行命令删除远程azure资源组上的主题或队列。其中一个命令是“Get-AzureRmServiceBusQueue”

我在VST的托管代理中使用Azure Powershell任务(使用Azure资源管理器)。此任务正在使用Azure Powershell 2.0.1

当我执行释放时,代理返回此故障:

"[error]The term 'Get-AzureRmServiceBusQueue' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
我检查了ServiceBus cmdlet是否仅在较新版本的Azure Powershell中提供(例如:最新的4.3.1)


我可以执行“安装模块-名称AzureRM”吗

根据您的描述,我在实验室进行测试。目前,如果您使用最新版本的Azure PowerShell,VSTS任务将使用4.2.1版本。cmdlet
Get-AzureRmServiceBusQueue
可用于我的任务

我使用的代理队列
托管VS2017
。这是我得到的日志

2017-08-25T02:34:00.0731521Z ##[section]Starting: Azure PowerShell script: InlineScript
2017-08-25T02:34:00.0911526Z ==============================================================================
2017-08-25T02:34:00.0921520Z Task         : Azure PowerShell
2017-08-25T02:34:00.0921520Z Description  : Run a PowerShell script within an Azure environment
2017-08-25T02:34:00.0921520Z Version      : 2.0.1
2017-08-25T02:34:00.0921520Z Author       : Microsoft Corporation
2017-08-25T02:34:00.0921520Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
2017-08-25T02:34:00.0921520Z ==============================================================================
2017-08-25T02:34:02.8332045Z ##[command]Import-Module -Name C:\Modules\azurerm_4.2.1\AzureRM\4.2.1\AzureRM.psd1 -Global
2017-08-25T02:34:11.8296290Z ##[command]Import-Module -Name C:\Modules\azure_4.2.1\AzureRM.Profile\3.2.1\AzureRM.Profile.psm1 -Global
2017-08-25T02:34:15.2798961Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant ******** -Credential System.Management.Automation.PSCredential -Environment AzureCloud
2017-08-25T02:34:16.1729615Z ##[command]Select-AzureRMSubscription -SubscriptionId 3b4d41fa-****-****-bc11-13d221b3b77d -TenantId ********
2017-08-25T02:34:16.3229723Z ##[command]& 'd:\a\_temp\a063a14b-863f-4439-bd37-29f7ee515754.ps1' 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z     Directory: C:\Modules\azure_4.2.1
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z 
2017-08-25T02:34:16.9640151Z ModuleType Version    Name                                ExportedCommands                                             
2017-08-25T02:34:16.9640151Z ---------- -------    ----                                ----------------                                             
2017-08-25T02:34:16.9640151Z Script     4.2.1      Azure                               {Get-AzureAutomationCertificate, Get-AzureAutomationConnec...
2017-08-25T02:34:16.9650152Z 
2017-08-25T02:34:16.9650152Z 
2017-08-25T02:34:16.9650152Z     Directory: C:\Program Files\WindowsPowerShell\Modules
另外,你可以参考这个

托管:AzureRM PowerShell 3.6.0

托管VS2017:AzureRM PowerShell 4.1.0(根据我的测试,目前的版本是4.2.1)


您需要使用托管的2017生成代理


2.0.1版本是Azure PowerShell任务的版本,而不是PowerShell版本,您可以使用以下代码检查PowerShell版本:
Write Output$PSVersionTable.PSVersion

我没有使用VST,也没有要测试的帐户,但是,如果它运行的是PowerShell版本5或更高版本,则应该能够运行install cmdlet,如图所示。您还可以将其与
-RequiredVersion
参数结合使用,以确保每个版本的版本一致。@Patrick Peters Use hosted 2017 bulid agent是否适合您?