How to set the calendar permission for a group so that only the group administrator has the editing permission, while the group users only have the viewing permission?

Albert Tang 0 Reputation points
2025-11-07T08:13:26.88+00:00

连接 Microsoft Graph(需要管理员权限)

Connect-MgGraph -Scopes "Group.ReadWrite.All", "Directory.Read.All", "Calendars.ReadWrite"

定义目标组名称(修改为您要管理的组名)

$groupName = "HC School wide"

获取目标组ID和所有者(管理员)信息

$targetGroup = Get-MgGroup -Filter "displayName eq '$groupName'" -Top 1

if (-not $targetGroup) {

Write-Error "找不到组: $groupName"

exit

}

$groupId = $targetGroup.Id

$groupOwners = Get-MgGroupOwner -GroupId $groupId

获取当前日历权限(清理旧权限)

$currentPermissions = Get-MgGroupCalendarPermission -GroupId $groupId

foreach ($permission in $currentPermissions) {

Remove-MgGroupCalendarPermission -GroupId $groupId -CalendarPermissionId $permission.Id

Write-Host "已移除旧权限: $($permission.EmailAddress)"

}

为组管理员添加 Write 权限

foreach ($owner in $groupOwners) {

$ownerUser = Get-MgUser -UserId $owner.Id

New-MgGroupCalendarPermission -GroupId $groupId -BodyParameter @{

    "emailAddress" = @{ "address" = $ownerUser.Mail }

    "role" = "write"

}

Write-Host "已授予管理员权限 (Write): $($ownerUser.Mail)"

}

为所有成员添加 Read 权限

$groupMembers = Get-MgGroupMember -GroupId $groupId

foreach ($member in $groupMembers) {

$memberUser = Get-MgUser -UserId $member.Id

if ($memberUser.Mail -and $groupOwners.Id -notcontains $member.Id) {

    New-MgGroupCalendarPermission -GroupId $groupId -BodyParameter @{

        "emailAddress" = @{ "address" = $memberUser.Mail }

        "role" = "read"

    }

    Write-Host "已授予成员权限 (Read): $($memberUser.Mail)"

}

}

Write-Host "`n操作完成!权限已更新:"

Get-MgGroupCalendarPermission -GroupId $groupId | Select-Object EmailAddress, Role

Microsoft Security | Microsoft Entra | Other

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.