Azure自动化-使用AD用户登录会引发错误

我正在尝试使用我的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                  
sdl2874 回答:Azure自动化-使用AD用户登录会引发错误

看着该错误,我没有看到登录或凭据问题。错误发生在get-AzureRmResourceGroup 在上下文中未找到订阅

当提供的凭证没有订阅时,会发生这种情况。如果您确定帐户已订阅,则问题可能出在Azure自动化中加载的模块上。

本文链接:https://www.f2er.com/3049615.html

大家都在问