2017-08-24 37 views
0

我想要執行命令以刪除遠程天青資源組上的主題或隊列。其中一個命令是'Get-AzureRmServiceBusQueue'。如何在VSTS任務中使用最新的AzureRM

我在VSTS的託管代理中使用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小命令在Azure中的PowerShell較新版本僅供(例如:最新的4.3.1)。

我可以執行'Install-Module -Name AzureRM'嗎?

+1

我沒有使用VSTS,也沒有帳戶可以測試,但是,如果它正在運行PowerShell版本5或更高版本,您應該能夠運行安裝cmdlet,如圖所示。您還可以將它與'-RequiredVersion'參數結合使用,以確保您獲得每個版本的一致版本。 – Persistent13

回答

2

根據你的描述,我在我的實驗室測試。目前,如果您使用最新版本的Azure PowerShell,則VSTS任務使用4.2.1版本。 cmdlet Get-AzureRmServiceBusQueue適用於我的任務。

enter image description here

代理隊列我用Hosted 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 

另外,你可以參考這個link:Hosted agents

託管:AzureRM PowerShell的3.6.0

託管VS2017:AzureRM PowerShell的4.1.0(根據我的測試,目前的版本是4.2.1)。

+0

@Patrick Peters使用託管的2017年bulid代理可以爲您工作嗎? –

+0

Thx Walter,這是正確的解決方案! –

0

您需要使用託管的2017構建代理

2.0.1版本是Azure中的PowerShell任務版本,而不是PowerShell的版本,你可以用這個代碼檢查的PowerShell版本:Write-Output $PSVersionTable.PSVersion

相關問題