您是否可以通过PowerShell授予对Azure应用程序的管理员访问权限

时间:2015-06-03 00:49:30

标签: azure adal

有没有办法只使用PowerShell授予应用程序管理同意权?想象一下,您已完成Connect-MsolService并提供了作为租户管理员的帐户的凭据;有没有办法根据应用程序客户端ID提供租户范围内的同意?

1 个答案:

答案 0 :(得分:0)

澄清一下,您的意思是授予应用程序作为管理员访问目录的能力吗?

如果是这种情况,您可以这样做:

# Using the Windows Azure Active Directory Module for Windows PowerShell
#
# Connect to the tenant to modify
Connect-MsolService # => login

# Get Service Principal to add the role to
$servicePrincipal = Get-MsolServicePrincipal -ServicePrincipalName Principal.Name

# Get role object ID
# Alternatively, you can list all the roles (in order to get a different role name) using just `Get-MsolRole`
$roleId = (Get-MsolRole -RoleName "Directory Readers").ObjectId

# Add role to service principal
Add-MsolRoleMember -RoleObjectId $roleId -RoleMemberObjectId     $servicePrincipal.ObjectId -RoleMemberType servicePrincipal

# Check our work
Get-MsolRoleMember -RoleObjectId $roleId # => should include Principal.Name in list

从这里开始:https://social.msdn.microsoft.com/Forums/azure/en-US/f12c15b7-e2cc-4056-8f0c-1dbfceaeec24/error-adding-service-principal-to-role-this-role-does-not-exist-check-the-name-and-try-again?forum=WindowsAzureAD&prof=required

同意应用程序请求的权限(通过其RequiredResourceAccess)只能在授权过程中通过ADAL完成。