随着Microsoft在所有产品和服务中增强其安全态势,API 功能发生了 更改 ,可能会影响以前依赖仅应用权限来使用 API 预配课堂笔记本和课堂团队的客户。
注意: 在大多数情况下,我们建议使用学校数据同步 (SDS) ,这是一项免费服务,可帮助自动执行将学生信息或管理系统中的用户和名册数据与 Microsoft 365 同步的过程。 SDS 可帮助你管理教育组织、用户、课堂和角色,将你的数据与 Microsoft Entra ID 和 Microsoft 365 同步,以便您可以使用 Microsoft Teams、教育版Intune、Exchange Online、SharePoint Online、OneNote 课堂笔记本,并启用单一登录集成的第三方应用。
你仍可以使用 PowerShell 和 Microsoft Graph 通过遵循支持的方法大规模预配类和笔记本。 本文概述了相关步骤,并提供相关文档的链接。
重要: 如果你正在与第三方合作伙伴合作大规模预配类,请在自行执行步骤之前与他们共享本文。
预配新类
选项 1 (建议) :使用 Teams PowerShell
警告: 在 2025 年 8 月 21 日之前,本文档的先前版本建议在进行所需更新之前通过 Teams PowerShell 进行预配。 这些更新现已完成, 此时可以继续使用此方法。 请耐心等待,谢谢。
使用 Teams PowerShell 预配新类非常简单,其中包括课程和笔记本的所有必要设置。 只需在以下脚本中自定义所需的显示名称,然后以管理员身份运行它。
示例脚本
# Using the Teams PowerShell SDK
Install-Module -MicrosoftTeams -Force -AllowClobber
New-Team -DisplayName 'Test Class 20251208.4' -Template 'EDU_Class'
|
选项 2:使用 Microsoft Graph PowerShell
如果无权访问 Teams PowerShell,则可能需要使用 Microsoft Graph 大规模探索预配类。 根据需要编辑以下脚本顶部的参数,然后以管理员身份运行脚本,以大规模预配类和笔记本:
示例脚本
# Using the MS Graph API
Install-Module Microsoft.Graph -AllowClobber -Force
# PARAMETERS
$Name = "Test Class 20251208.3"
$Description = "A Test Class"
$Mail = $Name -replace '[^a-zA-Z0-9\s]|[ ]', '' # Replace this mail alias with a preferred generation method
$OwnerId = "000-000-00000-000000-000" # Replace this with the Owner's GUID
# ------------
# Create a new M365 Group
$CreateGroupBody = @"
{
"description": "$Name",
"displayName": "$Description",
"groupTypes": [
"Unified"
],
"mailEnabled": false,
"mailNickname": "$Mail",
"securityEnabled": false,
"members@odata.bind": [
"https://graph.microsoft.com/v1.0/users/$OwnerId"
],
"owners@odata.bind": [
"https://graph.microsoft.com/v1.0/users/$OwnerId"
],
"visibility": "HiddenMembership",
"creationOptions": [
"ExchangeProvisioningFlags:461",
"classAssignments"
],
"extension_fe2174665583431c953114ff7268b7b3_Education_ObjectType": "Section",
"resourceBehaviorOptions": [
"appRoleForSite:22d27567-b3f0-4dc2-9ec2-46ed368ba538:fullcontrol",
"appRoleForSite:c9a559d2-7aab-4f13-a6ed-e7e9c52aec87:fullcontrol",
"appRoleForSite:13291f5a-59ac-4c59-b0fa-d1632e8f3292:fullcontrol",
"appRoleForSite:2d4d3d8e-2be3-4bef-9f87-7875a61c29de:fullcontrol",
"appRoleForSite:8f348934-64be-4bb2-bc16-c54c96789f43:fullcontrol"
]
}
"@
$NewGroup = Invoke-MgGraphRequest -uri 'https://graph.microsoft.com/v1.0/groups/' -Body $CreateGroupBody -Method POST -ContentType "application/json"
# Create Teams Class Team from group
$CreateTeamBody = @{
"template@odata.bind" = "https://graph.microsoft.com/v1.0/teamsTemplates('educationClass')"
"group@odata.bind" = "https://graph.microsoft.com/v1.0/groups('$($NewGroup.Id)')"
}
New-MgTeam -BodyParameter $CreateTeamBody
|
故障排除:向现有类网站授予权限
注意: 此方法还要求运行脚本的人员是站点管理员,如此 处所述。 下面的脚本包括一个步骤,用于将当前登录的用户添加为需要故障排除的站点的站点管理员。
如果已预配类,并且观察到课堂笔记本或 Teams 作业失败或权限问题,则可以使用以下脚本更新课堂的站点权限,将 rawGroups 参数替换为受影响类的 groupID:
示例脚本
#You will need to connect to SharePoint, Exchange Online, and Graph with the following -Scopes Sites.FullControl.All, as well as collect the groupIDs of Class Teams affected
$rawGroups =@("b0a5905d-09ae-4605-8e12-94da93ecbe92","e0eec729-24ef-451e-b079-56d0baf4dfc9")
# Convert to array of objects with .groupid
$groups = $rawGroups | ForEach-Object { Get-UnifiedGroup -Identity $_ }
$step = 0
#get the currently logged in user's account to add as a site admin
$CUA = (get-mgcontext).account
foreach ($group in $groups) {
$step = $step + 1
Set-SPOUser -Site $group.SharePointSiteUrl -LoginName $CUA -IsSiteCollectionAdmin $true
Write-Host "SiteCollectionAdmin added on $step of $($Groups.Count) Class Sites"
}
#Pause for 5 minutes before tiggering the General Folder creation
Write-Host "Pausing for 5 Minutes before adding perms to allow SiteCollectionAdmin to propagate"
Start-Sleep -Seconds 300
Write-Host "Working on $($Groups.Count) Classes"
foreach ($group in $groups) {
#$step = $step + 1
$Site = Get-MgGroupSite -GroupId $group.ExternalDirectoryObjectId -SiteId "root"
$SiteId = $Site.Id
Write-Host "Processing permissions on $step of $($Groups.Count) Classes"
# These are the AppIds for common Microsoft EDU Apps
$AppIds = @{
"8f348934-64be-4bb2-bc16-c54c96789f43"="EDU Assignments";
"22d27567-b3f0-4dc2-9ec2-46ed368ba538"="Reading Assignments";
"2d4d3d8e-2be3-4bef-9f87-7875a61c29de"="OneNote";
"c9a559d2-7aab-4f13-a6ed-e7e9c52aec87"="Microsoft Forms";
"13291f5a-59ac-4c59-b0fa-d1632e8f3292"="EDU OneNote";
}
# Apply the permissions to the group site
$AppIds.Keys | %{
$AppId = $_
$Name = $AppIds[$_]
$Body = @"
{
"roles": ["fullcontrol"],
"grantedToIdentities": [{
"application": {
"id": "$AppId",
"displayName": "$Name"
}
}]
}
"@
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/sites/$SiteId/permissions" -Body $Body -ContentType "application/json"
}
}
Write-Host "Processed $($Groups.Count) Classes, removing sitecollectionadmin"
$step = 0
foreach ($group in $groups) {
$step = $step + 1
Set-SPOUser -Site $group.SharePointSiteUrl -LoginName $CUA -IsSiteCollectionAdmin $false
Write-Host "SiteCollectionAdmin removed on $step of $($Groups.Count) Class Sites"
}
|