powershell - Azure PowerShell Start-AzureAutomationRunbook 未指定默认订阅

标签 powershell azure azure-devops azure-pipelines-build-task azure-automation

VSTS 上的 Azure PowerShell v2.* 能够执行

Get-AzureRmResourceGroup

成功并返回正确的结果...好!这有望证明 VSTS 和 Azure 帐户之间的身份验证按预期工作。

当我尝试以下命令时:

Start-AzureAutomationRunbook -AutomationAccountName "automationaccountname" -Name "RunbookName"

我得到这个:

No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default subscription.

但是,VSTS 之前已经自动执行这些命令:

Add-AzureRMAccount -ServicePrincipal -Tenant ******** -Credential System.Management.Automation.PSCredential -EnvironmentName AzureCloud
Select-AzureRMSubscription -SubscriptionId 12345678-1234-1234-1234-1234567890AB -TenantId ********

我不确定需要执行什么,因为上一个命令已选择订阅。有什么线索吗?

最佳答案

所以事情是这样的。此时有两个适用于 PowerShell 的 Azure 模块。有 Azure 和 AzureRM。 Azure 模块处理“经典”模型资源,而 AzureRM 模块则处理 ARM(Azure 资源管理)资源。它们中的每一个都或多或少地彼此独立运作,偶尔有一些小的重叠。这里的关键是任何以 *-AzureRM* 开头的内容都与 AzureRM 模块相关。这些 cmdlet 使用来自 Add-AzureRMAccount cmdlet 和 Set-AzureRMContext(Select-AzureRMSubscription 是别名)的登录信息。如果您运行的命令不是以“*-AzureRM”开头,那么您很可能需要通过 Add-AzureAccount cmdlet 登录到经典模块能够执行该命令,或者如果您已经执行了该操作,则只需使用 Select-AzureSubscription cmdlet 指定要使用的订阅即可。

最可能的解决方法:仔细检查这是否是经典 Runbook。如果它没有显示“经典”,请尝试使用 AzureRM 命令:

Start-AzureRmAutomationRunbook -AutomationAccountName "automationaccountname" -Name "RunbookName"

如果这不起作用,那么您需要确保您已登录到经典模块,并且可以查看您的订阅:

Get-AzureSubscription -SubscriptionId 12345678-1234-1234-1234-1234567890AB

如果您可以看到订阅,则可以运行相同的操作,只需将其通过管道传输到 Select-AzureSubscription

Get-AzureSubscription -SubscriptionId 12345678-1234-1234-1234-1234567890AB | Select-AzureSubscription

如果您没有看到列出的订阅,您可以使用 Add-AzureAccount cmdlet 使用与该订阅关联的帐户登录 Azure,然后重复 Get/Select-根据需要订阅 cmdlet。

关于powershell - Azure PowerShell Start-AzureAutomationRunbook 未指定默认订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45742860/

相关文章:

windows - 将 powershell 的输出保存在 CSV 文件中

json - 在Powershell中合并JSON对象

azure - PublishCucumberReport - 找不到 cucumber 报告的输出路径

angular - 使用 Yarn 部署构建时出错 - Angular 应用程序

azure-devops - 从 VSTS 设置应用程序标识的文件夹权限?

powershell - ShouldProcess 在 PowerShell7 中失败

powershell - 使用 Powershell 替换文件中的多行文本,而不使用 Regex

c# - 如何在 Azure Fluent API for SQL Server 中为现有数据库设置服务器级别目标(定价层)?

Azure API管理: X-Forwarded-Host,获取原始主机

asp.net-mvc - 适用于 Web 的 Azure 应用程序见解,在 Power BI 中显示唯一用户