隨著 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 佈建新班級很簡單,這將包括班級和筆記本的所有必要設定。 只需在以下腳本中自訂所需的顯示名稱並以管理員身份運行它即可。
重要
下列指令碼要求您使用 7.3.1 版 或更新版本的 Microsoft 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 大規模佈建班級。 視需要編輯下列指令碼頂端的參數,然後以系統管理員身分執行指令碼,以大規模佈建班級和 Notebook:
範例指令碼
# 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 triggering 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"
}