gpt4 book ai didi

azure-powershell - 在 Azure 中运行 Powershell 脚本时如何防止错误 "WARNING: Unable to acquire token for tenant ' 租户 ID'"

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

我正在使用 Powershell 脚本创建要用作 Azure 自动化的 Azure Runas 帐户的服务主体。该脚本有效,但是当它完成时我收到以下警告
警告:无法获取租户“tenantID”的 token 。

警告消息中的租户 ID 是我的帐户有权访问的另一个租户,其中包含多个订阅。但是,它与我登录的租户 ID 和订阅无关。

我试过通过 Powershell 窗口登录,然后在脚本中没有登录的情况下运行脚本,但得到相同的错误。当我在脚本运行后在 Powershell 窗口中运行 get-AzContext 时,它会列出正确的租户 ID

用于登录的功能如下。租户 ID 与我收到警告的 ID 不同

function Login {
# Log in
$tenantid = "tenantID"
$subscriptionId = "subscriptionID"
$subscriptionName = "subscriptionname"
Clear-AzContext -Force
Message("Logging In")
$account = $(Get-AzContext).Account
if ([string]::IsNullOrEmpty($account)) {
Login-AzAccount -Tenant $tenantid -Subscription $subscriptionId
}
# Select the subscription

Message("Selecting the '$subscriptionName' Subscription")
Set-AzContext $subscriptionId | Out-Null
}


I have no other references to tenantID. The only other reference I have is for the subscriptionID, in a script which is called by the original script.
$Subscription = $(Get-AzContext).Subscription

I'd like to understand why it's trying to access the different TenantID for a token, and not to have the error when running the script

最佳答案

登录

Connect-AzAccount

检查您当前的可用订阅
Get-AzContext -ListAvailable

选择您要处理的订阅
Select-AzContext -Name ''

关于azure-powershell - 在 Azure 中运行 Powershell 脚本时如何防止错误 "WARNING: Unable to acquire token for tenant ' 租户 ID'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58762844/

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