1
votes

I want to execute a command to remove a topic or queue on a remote azure resource group. One of the commands is 'Get-AzureRmServiceBusQueue'.

I use the Azure Powershell task (using the Azure Resource Manager) within a hosted agent of VSTS. This task is using the Azure Powershell 2.0.1.

When I perform the release the agent is returning this failure:

"[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."

I checked that the ServiceBus cmdlet is only provided in newer versions of the Azure Powershell (for example: the latest 4.3.1).

Can I perform a 'Install-Module -Name AzureRM' ?

2
I have not used VSTS nor do I have an account to test with, but, if it is running PowerShell version 5 or later you should be able to run the install cmdlet as shown. You can also combine it with the -RequiredVersion parameter to be sure you get a consistent version for each build.Persistent13

2 Answers

2
votes

According to your description, I test in my lab. Currently, if you use the latest version Azure PowerShell, VSTS task uses 4.2.1 version. cmdlet Get-AzureRmServiceBusQueue works on my task.

enter image description here

Agent queue I use Hosted VS2017. Here is the log I get.

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

Also, you could refer to this link:Hosted agents.

Hosted: AzureRM PowerShell 3.6.0

Hosted VS2017:AzureRM PowerShell 4.1.0(According to my test, currently, the version is 4.2.1).

1
votes

You need to use Hosted 2017 build agent.

The 2.0.1 version is the Azure PowerShell Task version instead of PowerShell version, you can check PowerShell version with this code: Write-Output $PSVersionTable.PSVersion.