简体   繁体   English

Azure 自动化 RunAs 帐户访问 Active Directory 资源

[英]Azure Automation RunAs account access to Active Directory resource

I am trying to create a Runbook which does some maintenance in Active Directory.我正在尝试创建一个在 Active Directory 中进行一些维护的 Runbook。 On creation of an Automation Account an "RunAs" account was created.在创建自动化帐户时,会创建一个“RunAs”帐户。 In the runbook I connect to AD using the below command.在运行手册中,我使用以下命令连接到 AD。

$connectionName = "AzureRunAsConnection"

# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

"Logging in to AzureAD..."
Connect-AzureAD `
 -TenantId $servicePrincipalConnection.TenantId `
 -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint `
 -ApplicationId $servicePrincipalConnection.ApplicationId `
 -LogLevel Info

This command runs fine, however the subsequent use of AD CMDLETS gives the following error,此命令运行良好,但随后使用 AD CMDLETS 会出现以下错误,

$Users = Get-AzureADUser
Get-AzureADUser : Error occurred while executing GetUsers Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation. 
HttpStatusCode: Forbidden 
HttpStatusDescription: Forbidden 
HttpResponseStatus: Completed

The same is true for other CMDLETS in the AD module, not just this I have tried adding API permission through the registered application (relating to the Automation Account connection resource) in Active Directory but I am still facing the above privileges issue. AD 模块中的其他 CMDLETS 也是如此,不仅如此,我还尝试通过 Active Directory 中的注册应用程序(与自动化帐户连接资源相关)添加 API 权限,但我仍然面临上述权限问题。

According to some test, you need to add the permissions of Azure AD but not Micorsoft Graph.根据一些测试,您需要添加 Azure AD 而不是 Micorsoft Graph 的权限。 It seems the Get-AzureADUser command use Azure AD graph in the backend.似乎Get-AzureADUser命令在后端使用 Azure AD 图。 So we need to do the operations as below:所以我们需要进行如下操作: 在此处输入图像描述

在此处输入图像描述

After that we can use the command Get-AzureADUser successfully( if you test the command in powershell, when you add the Azure AD permission, please close the powershell and reopen it and re-connect )之后我们就可以使用命令Get-AzureADUser成功了(如果你在powershell中测试命令,当你添加Azure AD权限时,请关闭Z2F2D399F0EA8844859FE5514B304733重新连接B

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM