更改密码时权限不足

时间:2019-01-28 14:27:52

标签: azure-active-directory azure-powershell

我正在尝试在docker容器中使用Azure Powershell(AZ powershell模块)来创建/修改与Office 365相关的配置,包括用户配置文件。

我正在尝试使用服务主体更改用户密码。使用Update-AzADUser时出现以下错误。但是,我可以创建用户并修改显示名称。我只有更改密码或删除用户时遇到问题。

  

PS /> Update-AzADUser -ObjectId xyz358c2... -Password $password
  Update-AzADUser:特权不足,无法完成操作。
  在第1行:char:1
  + Update-AzADUser -ObjectId xyz358c2... -Passw ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
  + CategoryInfo:InvalidOperation :( :) [Update-AzADUser],异常
  + FullyQualifiedErrorId:Microsoft.Azure.Commands.ActiveDirectory.UpdateAzureADUserCommand

关于服务主体,我提供了 Microsoft Graph API Windows Azure Active Directory 上的所有可用应用程序权限和委派权限。

我找不到https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/directory-assign-admin-roles中可用于分配给服务主体的任何AD角色。请在以下链接上截图。

Permissions

Roles

1 个答案:

答案 0 :(得分:0)

如评论中所述,您应该尝试为所使用的服务主体分配适当的目录角色,以便它可以获得足够的特权。

这是执行此操作的快速脚本。根据您的要求更改服务主体名称和roleName。

# Get to the service principal
$svcPrincipalId = (Get-AzureADServicePrincipal -SearchString "your service principal name").ObjectId

# I am using Helpdesk administrator here, but feel free to change this name as per your requirement. 
# You can get a complete list of role templates using Get-AzureADDirectoryRoleTemplate. 
# Helpdesk admninstrator role can reset passwords for non-administrators.
$roleName = 'Helpdesk administrator'

# Fetch User Account Administrator role instance
$role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq $roleName}

# If role instance does not exist, instantiate it based on the role template
if ($role -eq $null) {

    # Instantiate an instance of the role template
    $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object {$_.displayName -eq $roleName}
    Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId

    # Fetch User Account Administrator role instance again
    $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq $roleName}
}


# Add user to role
Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId $svcPrincipalId
相关问题