[英]Azure Automation - Login with AD User throws error
I am trying to login to Azure from Azure Automation using my AD credential.我正在尝试使用我的 AD 凭据从 Azure 自动化登录到 Azure。 However seems like I am doing something wrong and it's throwing error while testing.
但是,好像我做错了什么,并且在测试时抛出了错误。
$Cred = Get-AutomationPSCredential -Name 'DefaultAzureCredential'
$null = Add-AzureRmAccount -Credential $Cred -ErrorAction Stop -ErrorVariable err
if($err) {
throw $err
}
Get-AzureRmResourceGroup -Name "my-resource-group"
Error:错误:
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
Update:更新:
When I run Get-AzureRm-Context
from Azure Automation script it shows me following which is completely different than when I run the same command from Azure Cloud Shell
.当我从 Azure 自动化脚本运行
Get-AzureRm-Context
时,它显示我遵循的操作与从Azure Cloud Shell
运行相同命令时完全不同。 Should I do things differently?我应该做不同的事情吗?
Account Environment Subscription Tenant
------- ----------- ------------ ------
AzureCloud
Looking at the error, i do not see an issue with Login or credential.查看错误,我没有看到登录或凭据的问题。 The error is in the
get-AzureRmResourceGroup
No subscription found in the context .错误出现在
get-AzureRmResourceGroup
No subscription found in the context 中。
This happens when credential provided does not have a subscription.当提供的凭据没有订阅时会发生这种情况。 If you are sure account has subscription, then the issue might be with the module loaded in Azure Automation.
如果您确定帐户已订阅,则问题可能出在 Azure 自动化中加载的模块上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.