我正在尝试使用我的 AD 凭据从 Azure 自动化登录到 Azure。然而,似乎我做错了什么,并且在测试时抛出错误。
$Cred = Get-AutomationPSCredential -Name 'DefaultAzureCredential'
$null = Add-AzureRmAccount -Credential $Cred -ErrorAction Stop -ErrorVariable err
if($err) {
throw $err
}
Get-AzureRmResourceGroup -Name "my-resource-group"
错误:
Get-AzureRmResourceGroup : No subscription found in the context. Please ensure that the credentials you provided are
authorized to access an Azure subscription, then run Login-AzureRMAccount to login.
At line:8 char:1
+ Get-AzureRmResourceGroup -Name "my-resource-group"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureRmResourceGroup], ApplicationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.GetAzureResourceGroupCommand
更新:
当我从 Azure 自动化脚本运行 Get-AzureRm-Context
时,它会显示以下内容,这与我从 Azure Cloud Shell
运行相同命令时完全不同。我应该采取不同的做法吗?
Account Environment Subscription Tenant
------- ----------- ------------ ------
AzureCloud
最佳答案
查看错误,我没有发现登录或凭据有问题。错误位于 get-AzureRmResourceGroup
在上下文中找不到订阅。
当提供的凭据没有订阅时,就会发生这种情况。如果您确定帐户已订阅,则问题可能与 Azure 自动化中加载的模块有关。
关于Azure 自动化 - 使用 AD 用户登录会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997869/