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

标签 azure azure-automation azure-authentication

我正在尝试使用我的 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/

相关文章:

azure - “RetryPolicy”是一个不明确的引用

azure-sql-database - Azure Analysis Services 是否支持服务主体登录 SQL Azure

Angular 应用程序托管 Azure 存储容器 - Azure 身份验证回调和路由失败

azure - Auth0 的合适 Azure 替代品

asp.net - Azure Web App EasyAuth 回调抛出错误

entity-framework - Entity Framework 二级缓存和Windows Azure缓存

azure - Azure 搜索索引中的异步或同步复制?

php - 在 Windows Azure 上运行 PHP

azure - Runbook 模块部署失败,因为它达到了终端预配状态 'Failed'

powershell - Azure 资源管理器 powershell cmdlet 在 azure 门户测试 Pane (自动化帐户)上无法识别