Azure active directory 更改密码时权限不足

Azure active directory 更改密码时权限不足,azure-active-directory,azure-powershell,Azure Active Directory,Azure Powershell,我正在尝试在docker容器内使用Azure Powershell(AZ Powershell模块)创建/修改office 365相关配置,包括用户配置文件 我正在尝试使用服务主体更改用户密码。我在使用更新AzADUser时出现以下错误。但是,我可以创建用户并修改显示名称。我只是在更改密码或删除用户时遇到问题 PS/>更新AzADUser-ObjectId xyz358c2-密码$Password 更新AzADUser:权限不足,无法完成操作。 第1行字符:1 +更新AzADUser-Objec

我正在尝试在docker容器内使用Azure Powershell(AZ Powershell模块)创建/修改office 365相关配置,包括用户配置文件

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

PS/>
更新AzADUser-ObjectId xyz358c2-密码$Password

更新AzADUser:权限不足,无法完成操作。
第1行字符:1
+
更新AzADUser-ObjectId xyz358c2-密码…

+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +类别信息:无效操作:(:)[更新AzADUser],异常
+FullyQualifiedErrorId:Microsoft.Azure.Commands.ActiveDirectory.UpdateAzureADUserCommand

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

我找不到中可用于分配给服务主体的任何AD角色。请在下面的链接上截图


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

这里有一个快速脚本来实现这一点。根据您的要求更改服务主体名称和角色名称

# 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

是 啊这些是高度特权的行动。要允许主体使用这些角色,您可能需要使用PowerShell为服务主体分配目录角色。您可以在此处看到可用角色的列表:。非常感谢您的回复!我已经在另一个堆栈overflow线程中查看了类似的注释。我有一台苹果电脑。如何使用Powershell Core或Azure Powershell添加目录角色?我认为@juunas的建议是一个很好的建议(通常我可能会添加)。。回答有关如何使用PowerShell为服务主体添加目录角色的问题。。您可以结合使用
添加AzureAddirectoryMember
获取AzureADServicePrincipal
。。在目录角色方面,类似于帮助台Admnistrator的功能至少应该用于重置非管理员用户的密码。。如果需要,您可以根据自己的需求选择一个更具特权的目录角色。@Shreedhar还知道,在某些情况下,RoleTemplate尚未启用。。因此,这将是一个脚本位。。我会试着看看我是否能快速测试一些东西并添加答案。非常感谢Rohit和Juunas。AzureAD是特定于windows的。我想知道你在Mac上是怎么做的。无论如何,我试图通过查找windows计算机来运行这些命令。我会随时通知你的。谢谢Rohit提供的详细信息。我会给你一个机会并告诉你最新情况。:-)非常感谢你的剧本。我使用公司管理员角色进行测试。它很有魅力!请记住,服务主体现在是全局管理员。。小心钥匙,朱纳斯!谢谢你提供的信息。很高兴它成功了。此外,公司管理员是一个高度特权角色,正如上面正确强调的@juunas。我在我的示例脚本中使用了Helpdesk Administrator,这对于大多数常见的场景应该是很好的。