You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何断开M365组与SharePoint Online团队站点关联并保留站点?

批量处理关联M365组/Teams的SharePoint站点操作指南

核心前提

必须先断开SharePoint站点与M365组的关联,否则删除M365组会直接删除站点。以下是分阶段的PowerShell操作步骤:

1. 断开SharePoint站点与M365组的关联

使用SharePoint Online PowerShell模块:

# 安装模块(首次运行)
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force

# 连接到SharePoint管理员中心
Connect-SPOService -Url https://<你的租户名>-admin.sharepoint.com

# 定义目标站点URL
$siteUrl = "https://<你的租户名>.sharepoint.com/sites/<站点名称>"
$site = Get-SPOSite -Identity $siteUrl

# 移除Hub站点关联(如果站点属于Hub)
Set-SPOSite -Identity $siteUrl -HubSiteAssociation $null

# 断开与M365组的绑定
Set-SPOSite -Identity $siteUrl -GroupId $null

2. 删除关联的Teams团队

使用Microsoft Teams PowerShell模块:

# 安装模块(首次运行)
Install-Module -Name MicrosoftTeams -Force

# 连接到Teams服务
Connect-MicrosoftTeams

# 通过M365组ID获取并删除Teams团队
$groupId = $site.GroupId
Remove-Team -GroupId $groupId -Confirm:$false

3. 删除M365组

使用Microsoft Graph PowerShell模块(推荐):

# 安装模块(首次运行)
Install-Module -Name Microsoft.Graph -Force

# 连接到Graph服务,需Group读写权限
Connect-MgGraph -Scopes "Group.ReadWrite.All"

# 删除目标M365组
Remove-MgGroup -GroupId $groupId -Confirm:$false

4. 重置SharePoint站点权限

清除旧的组权限,配置新的权限体系:

# 打破权限继承(确保站点权限独立)
Set-SPOSite -Identity $siteUrl -PermissionPolicyBlockInheritance $true

# 移除旧的M365组权限
$oldGroups = Get-SPOSiteGroup -Site $siteUrl | Where-Object { $_.LoginName -match $groupId }
foreach ($group in $oldGroups) {
    Remove-SPOSiteGroup -Site $siteUrl -Identity $group.LoginName -Confirm:$false
}

# 添加新站点管理员
Set-SPOUser -Site $siteUrl -LoginName "admin-user@domain.com" -IsSiteCollectionAdmin $true

# 创建并配置新权限组(示例)
# 编辑权限组
New-SPOSiteGroup -Site $siteUrl -Group "项目编辑组" -PermissionLevels "Edit"
Add-SPOUser -Site $siteUrl -LoginName "editor-user@domain.com" -Group "项目编辑组"

# 只读权限组
New-SPOSiteGroup -Site $siteUrl -Group "项目只读组" -PermissionLevels "Read"
Add-SPOUser -Site $siteUrl -LoginName "viewer-user@domain.com" -Group "项目只读组"

批量处理脚本示例

如果有大量站点,可将站点URL存入CSV(列名:SiteUrl),循环执行:

$sites = Import-Csv -Path "target-sites.csv"

foreach ($row in $sites) {
    $siteUrl = $row.SiteUrl
    $site = Get-SPOSite -Identity $siteUrl -ErrorAction SilentlyContinue
    if (-not $site) { continue }

    # 断开组关联
    Set-SPOSite -Identity $siteUrl -HubSiteAssociation $null
    Set-SPOSite -Identity $siteUrl -GroupId $null

    # 删除Teams和M365组
    $groupId = $site.GroupId
    if ($groupId) {
        Remove-Team -GroupId $groupId -Confirm:$false -ErrorAction SilentlyContinue
        Remove-MgGroup -GroupId $groupId -Confirm:$false -ErrorAction SilentlyContinue
    }

    # 重置权限(按需调整)
    Set-SPOSite -Identity $siteUrl -PermissionPolicyBlockInheritance $true
    $oldGroups = Get-SPOSiteGroup -Site $siteUrl | Where-Object { $_.LoginName -match $groupId }
    foreach ($group in $oldGroups) {
        Remove-SPOSiteGroup -Site $siteUrl -Identity $group.LoginName -Confirm:$false -ErrorAction SilentlyContinue
    }
    Set-SPOUser -Site $siteUrl -LoginName "default-admin@domain.com" -IsSiteCollectionAdmin $true
}

注意事项

  • 操作前务必备份站点内容,避免数据丢失。
  • 执行PowerShell命令需对应权限:SharePoint管理员、Teams管理员、Azure AD管理员权限。
  • 批量处理时建议先测试单个站点,确认流程无误后再扩大范围。

内容的提问来源于stack exchange,提问作者dashed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 15:55:27