azure 无法通过MS Graph修改组的autoSubscribeNewMembers

8fq7wneg  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(130)

我可以成功地在MS Graph中创建一个组。我试图更新autoSubscribeNewMembers属性,但当我这样做时,我收到一个错误:"User does not have permissions to execute this action."
下面是我使用的代码:

$groupData = @{
        displayName                 = 'TESTGROUPNAME'
        mailNickname                = 'TESTGROUPNAME'
        description                 = 'TESTGROUPNAME'
        visibility                  = 'Private'
        groupTypes                  = @('Unified')
        mailEnabled                 = $true
        securityEnabled             = $true
        "resourceBehaviorOptions"   = @("WelcomeEmailDisabled")
        "[email protected]"         = @('https://graph.microsoft.com/beta/users/<USERID>')

$newGroup   = Invoke-MgGraphRequest `
    -Uri 'https://graph.microsoft.com/beta/groups' `
    -Body $groupData `
    -Method POST

$updatePayload = @{autoSubscribeNewMembers=$true}
$response   = Invoke-MgGraphRequest                                             `
    -Uri        ('https://graph.microsoft.com/v1.0/groups/{0}' -f $newGroup.Id) `
    -Method     PATCH                                                           `
    -Body       $updatePayload                                                  `
    -OutputType HttpResponseMessage

字符串
在这一点上,我得到了描述的错误。
我已确认该应用程序确实具有所需的权限:


的数据
有谁能给我点建议吗?谢谢大家。

83qze16e

83qze16e1#

如本MS文档中所述,更新autoSubscribeNewMembers仅支持**Delegated权限。
当您在连接MS Graph时使用
基于证书的身份验证时,它使用应用程序类型的权限(仅应用程序访问),无法用于更新autoSubscribeNewMembers
我注册了一个Azure AD应用程序,并授予了类似的
API权限**,如下所示:


的数据
当我通过连接MS Graph与证书在我的环境中运行您的代码时,创建了新组,但更新autoSubscribeNewMembers属性失败,并出现相同的错误如下:

Connect-MgGraph  -TenantId "tenantId" -ClientId "appId" -CertificateThumbprint "xxxxxxxxxxxxxx" -NoWelcome

$groupData = @{
        displayName                 = 'SRITESTGROUP'
        mailNickname                = 'SRITESTGROUP'
        description                 = 'SRITESTGROUP'
        visibility                  = 'Private'
        groupTypes                  = @('Unified')
        mailEnabled                 = $true
        securityEnabled             = $true
        "resourceBehaviorOptions"   = @("WelcomeEmailDisabled")
        "[email protected]"         = @('https://graph.microsoft.com/beta/users/userId')
        }

$newGroup   = Invoke-MgGraphRequest `
    -Uri 'https://graph.microsoft.com/beta/groups' `
    -Body $groupData `
    -Method POST

Start-Sleep -Seconds 30

$updatePayload = @{autoSubscribeNewMembers=$true}
$response   = Invoke-MgGraphRequest                                             `
    -Uri        ('https://graph.microsoft.com/v1.0/groups/{0}' -f $newGroup.Id) `
    -Method     PATCH                                                           `
    -Body       $updatePayload                                                  `
    -OutputType HttpResponseMessage

字符串

回复:



解决错误,您需要使用交互式流连接使用Delegated权限的MS Graph。
在我的例子中,我运行了下面的命令,并以用户身份使用委派访问权限连接到MS Graph:

Disconnect-MgGraph
Connect-MgGraph -Scopes Group.ReadWrite.All



现在再次运行代码,new group成功创建并更新了autoSubscribeNewMembers属性,如下所示:

$groupData = @{
        displayName                 = 'TESTGROUPSRI'
        mailNickname                = 'TESTGROUPSRI'
        description                 = 'TESTGROUPSRI'
        visibility                  = 'Private'
        groupTypes                  = @('Unified')
        mailEnabled                 = $true
        securityEnabled             = $true
        "resourceBehaviorOptions"   = @("WelcomeEmailDisabled")
        "[email protected]"         = @('https://graph.microsoft.com/beta/users/userId')
        }

$newGroup   = Invoke-MgGraphRequest `
    -Uri 'https://graph.microsoft.com/beta/groups' `
    -Body $groupData `
    -Method POST

Start-Sleep -Seconds 30

$updatePayload = @{autoSubscribeNewMembers=$true}
$response   = Invoke-MgGraphRequest                                             `
    -Uri        ('https://graph.microsoft.com/v1.0/groups/{0}' -f $newGroup.Id) `
    -Method     PATCH                                                           `
    -Body       $updatePayload                                                  `
    -OutputType HttpResponseMessage

回复:



为了确认,我运行下面的命令,其中autoSubscribeNewMembers属性为true,如下所示:

Import-Module Microsoft.Graph.Groups
Get-MgGroup -GroupId $newGroup.Id -Property "displayName,autoSubscribeNewMembers" | Select-Object displayName,autoSubscribeNewMembers

回复:


相关问题