gpt4 book ai didi

powershell - 更改 Login-AzureRmAccount 的默认订阅

转载 作者:行者123 更新时间:2023-12-01 01:53:09 29 4
gpt4 key购买 nike

我的 Azure 帐户有两个与之关联的目录 - 一个用于生产环境,一个用于测试环境。目前,当我运行 Login-AzureRmAccount 时,它会登录到生产订阅。是否可以在 Azure RM 端配置一项设置,以便当我运行 Login-AzureRmAccount PowerShell cmdlet 时,它会自动登录到测试订阅?

我意识到我可以使用 Select-AzureRmSubscription 来更改订阅,但我正在寻找一种方法让它自动默认为我的首选订阅,而无需运行其他命令。 (事实上​​,这是与第 3 方工具一起使用的,该工具可自动执行 PowerShell 命令,因此我无法将其他参数或 Select-AzureRmSubscription 调用插入到流程中。)

最佳答案

与 ASM 的 -default 参数不同,目前无法更改 ARM 的默认订阅。

以下是使用 Powershell 配置文件的解决方法:

测试一下您是否已经拥有:

Test-Path $profile

如果为 False,则创建一个:

New-Item -path $profile -type file –force

然后将其添加到文件中:

$azureAccountName ="your username"
$azurePassword = ConvertTo-SecureString "your password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword)

Login-AzureRmAccount -Credential $psCred -TenantId "your tenant id" -SubscriptionId "your subscription id"

-Credential 参数仅适用于 Azure AD。如果您使用的是 Microsoft 帐户,则需要将其删除并每次手动登录。

关于powershell - 更改 Login-AzureRmAccount 的默认订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42636274/

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