gpt4 book ai didi

Azure Devops - Azure 资源管理器 (ARM) 服务连接

转载 作者:行者123 更新时间:2023-12-03 06:54:17 25 4
gpt4 key购买 nike

我有一个 PowerShell 脚本,我想将其移至 Azure DevOps 管道中。

PowerShell 脚本执行 Connect-AzAccount,然后迭代我的帐户可以看到的所有约 300 个订阅:

foreach ( $Subscription in $(Get-AzSubscription | Where-Object { $_.State -ne "Disabled" }) ) {...}

DevOps 管道使用 AzurePowerShell@5 任务中的服务连接:

- task:  AzurePowerShell@5
inputs:
azurePowerShellVersion: 'LatestVersion'
ConnectedServiceNameARM: test-infosec-connection
scriptPath: './_AzureWafCompliance.ps1'
pwsh: true

作业成功运行并完成,但问题是它仅迭代一个订阅,即 ARM 服务连接订阅。

在调试中可以看到 AzurePowerShell 任务运行以下命令:

Connect-AzAccount -ServicePrincipal -Tenant xxxxxxx-xxxxxxx-xxxxxx-xxxxxx-xxxxxx -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope

Set-AzContext -SubscriptionId xxxxxx-xxxx-xxxx-xxxx-xxxxxx -TenantId xxxx-xxxx-xxxx-xxxx-xxxxxx

我怀疑这是第二个命令将我锁定在订阅中。是否有另一种/更好的方法,或者有任何方法可以更改 AzurePowershell 任务的默认行为?

最佳答案

Azure PowerShell 任务用于在 Azure 环境中运行 PowerShell 脚本。 Azure 上下文通过提供的 Azure 资源管理器服务连接进行身份验证。

在本地,该脚本会使用您的凭据运行,并且会成功,因为您可能拥有所需的访问权限。

创建 ARM 服务连接订阅时,必须选择 Azure 订阅。

enter image description here

因此,您的 Azure PowerShell 任务仅迭代此选定的 Azure 订阅。

使用 ARM 服务连接管理组而不是 ARM 服务连接订阅:https://learn.microsoft.com/en-us/azure/governance/management-groups/overview

enter image description here

关于Azure Devops - Azure 资源管理器 (ARM) 服务连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73225539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com