gpt4 book ai didi

powershell - 用于构建服务器的 Azure 凭据

转载 作者:行者123 更新时间:2023-12-03 00:46:44 29 4
gpt4 key购买 nike

我在使用 Azure 时遇到身份验证问题。我有一个运行 powershell 脚本的连续构建服务器,我收到如下消息:

Your Azure credentials have not been set up or have expired, please run Login-AzureRMAccount to set up your Azure credentials.

我不喜欢在构建服务器上使用我的帐户登录。我想我可以创建另一个帐户只是为了构建,但它也会过期。有没有更好的方法来处理这个问题?

最佳答案

您不应在构建/部署脚本中使用 Login-AzureRmAccount,因为这是交互式登录,而应该使用 Add-AzureRmAccount相反。

Add-AzureRmAccount 需要您create a service principal (应用程序)在 Azure AD 中并使用其客户端 ID 和 key / key 进行身份验证。

以下是您可以使用的代码片段:

$clientID = "<the client id of your AD Application>"
$key = "<the key of your AD Application>"
$SecurePassword = $key | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential `
-argumentlist $clientID, $SecurePassword

Add-AzureRmAccount -Credential $cred -Tenant "xxxx-xxxx-xxxx-xxxx" -ServicePrincipal

找出您的租户 ID(单一订阅)

$tenant = (Get-AzureRmSubscription).TenantId

查找租户 ID(多个订阅)

$tenant = (Get-AzureRmSubscription -SubscriptionName "My Subscription").TenantId

关于powershell - 用于构建服务器的 Azure 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42911206/

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