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

标签 powershell azure azure-devops

我想要执行命令来删除远程 Azure 资源组上的主题或队列。命令之一是“Get-AzureRmServiceBusQueue”。

我在 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 cmdlet 仅在较新版本的 Azure Powershell 中提供(例如:最新的 4.3.1)。

我可以执行“Install-Module -Name AzureRM”吗?

最佳答案

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

enter image description here

代理队列我使用托管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 .

Hosted: AzureRM PowerShell 3.6.0

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

关于powershell - 如何在 VSTS 任务中使用最新的 AzureRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45858925/

相关文章:

azure-devops - 在 Azure Devops 中编写 EF6 迁移脚本

powershell - 尚未为 Windows PowerShell 版本 2 注册任何管理单元

rest - Azure Media Player - 在编码过程中显示编码进度或某种消息

Azure 函数需要很长时间才能触发

azure - 如何在azure devops api服务中传递具有多个值的对象参数

azure - 如何将 Azure 文件共享添加为 Azure Pipeline 中的卷

azure-devops - 将 NuGet 包从 TeamCity 发布到 Azure DevOps Artifacts

powershell - 使用Powershell卸载exe软件

Windows PowerShell。通过 PowerShell 命令运行程序

powershell - Powershell 中的德语变音符号。遍历目录不起作用