[玩转系统] SharePoint Online:使用 PowerShell 删除子网站
作者:精品下载站 日期:2024-12-14 14:15:11 浏览:13 分类:玩电脑
SharePoint Online:使用 PowerShell 删除子网站
要求:用于删除子网站的 SharePoint Online PowerShell。
如何删除 SharePoint Online 中的子网站?
您的 SharePoint Online 环境中是否存在不再需要的子网站?也许它是错误创建的或者不再使用。如果是的话,我们可以将其删除并释放一些存储空间!在这篇博文中,我将向您展示删除子网站的步骤,并分享一些如何使用 PowerShell 在 SharePoint Online 中删除子网站的脚本示例。这是一种快速、简单的清理环境的方法,只需几分钟即可完成。让我们开始吧!
任何具有“管理层次结构”或“完全控制”权限的用户都可以在不再需要时删除 SharePoint Online 中的网站。要从 SharePoint Online 删除子网站,请执行以下操作:
- 登录您的 SharePoint Online 站点 >> 单击“站点设置”齿轮 >> 选择“站点设置”。
单击“网站操作”组下的“删除此网站”链接。 (如果您没有看到“删除此网站”链接,则意味着您无权删除该网站,或者您正在使用现代团队网站或通信网站!)
-
这将引导您进入经典网站中的“删除此网站”页面。单击“删除”按钮并确认删除子网站。
- 您会收到“您的网站已被删除”的消息。一会儿留言。
SharePoint Online:如何删除子网站?
同样,在现代 SharePoint 网站上,您可以单击“设置”>> 网站信息 >> 删除网站。
选择“是,删除此网站及其相关内容”确认删除。复选框,然后单击“删除”按钮。删除网站时,您还将删除与该网站关联的所有资源,例如任何子网站、网站设置、用户信息、网站内容(例如与该网站关联的文档、文档库、列表和列表数据)。
使用网站和工作区删除 SharePoint Online 子网站
您还可以使用“网站和工作区”链接批量删除 SharePoint Online 中的子网站。具体方法如下:
- 导航到包含要删除的子网站的父网站。
- 单击设置齿轮 >> 选择站点设置
- 在“站点设置”页面的“站点管理”部分下,单击“站点和工作区”链接。
- 在“站点和工作区”页面上,单击要删除的子站点旁边的“删除”图标。
单击“删除”按钮 >> 单击“确定”按钮进行确认。
这将删除 SharePoint Online 中的子网站。删除 SharePoint Online 中的所有子网站是一项艰巨的任务。你可以这样做,但是当Sharepoint Online中有大量子网站时,将它们一一删除可能会很麻烦。因此,我们将展示如何使用 PowerShell 删除 SharePoint Online 中的子网站!
在执行这些脚本之前,您需要在计算机上安装 SharePoint Online Management Shell 或 CSOM SDK for SharePoint Online。您可以从这里下载 https://www.microsoft.com/en-in/download/details.aspx?id=35588如果您通过 Web 用户界面(而不是通过 PowerShell!)意外删除了子网站,网站集管理员可以从网站集回收站中恢复它。
使用 PowerShell 删除 SharePoint Online 中的子网站:
如何使用 PowerShell 删除 SharePoint Online 中的子网站?好吧,虽然使用 Web 浏览器 UI 删除 SharePoint Online 中的子网站相对简单,但在某些情况下我们可能需要 PowerShell,例如:
- 当您必须批量删除子站点时。
- 如果您想删除具有子站点的子站点(您将收到此错误:“删除网站“/sites/Sales/apac”时出现问题。具有子站点或某些应用程序的站点无法删除)请删除所有子网站并删除应用程序后重试。”)
以下是用于删除 SharePoint Online 中的子网站的 PowerShell:
#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/Marketing/townhall2019/"
Try{
#Get Credentials to connect
$Cred= Get-Credential
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the subsite to delete
$web = $Ctx.Web
$Ctx.Load($web)
$Ctx.ExecuteQuery()
#sharepoint online powershell remove subsite
$web.DeleteObject()
$Ctx.ExecuteQuery()
Write-Host "Subsite Deleted:" $web.Title -foregroundcolor Green
}
Catch{
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
此 PowerShell 脚本删除 SharePoint Online 子网站。请注意,这些方法会永久删除子网站,而不会将其发送到回收站(换句话说,如果通过 PowerShell 删除的子网站无法恢复)
如何使用 PowerShell 删除 SharePoint Online 中网站下的所有子网站?
让我们将上面的脚本包装成一个可重用的函数,以递归地删除网站集中的子网站!
#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = "https://portal.sharepoint.com/sites/Sales/apac/us/"
$UserName="[email protected]"
$Password ="password goes here"
#Function to delete a subsite and its all child sites
Function Remove-SPOWeb() {
param(
$WebURL = $(throw "Please Enter the Subsite URL to Remove:")
)
try{
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Get Web information and subsites
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$Context.Credentials = $credentials
#get the subsite
$web = $context.Web
$context.Load($web)
$Context.Load($web.Webs)
$Context.executeQuery()
#Iterate through each subsite in the current web
foreach ($Subweb in $web.Webs)
{
#Call the function recursively to process all subsites underneaththe current web
Remove-SPOWeb($Subweb.url)
}
#sharepoint online powershell delete web
$web.DeleteObject()
$context.ExecuteQuery()
Write-Host "SubSite Deleted:" $web.Title -foregroundcolor Green
}
catch{
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Call the function to remove subsite
Remove-SPOWeb -WebURL $SiteUrl
此 PowerShell 将删除 SharePoint Online 网站中的所有子网站。只需几行代码,您就可以节省大量时间和麻烦!
用于删除子网站的 SharePoint Online PnP PowerShell
要使用 PnP PowerShell 删除 SharePoint Online 中的子网站,请使用:Remove-PnPWeb PowerShell 命令。以下是使用 PnP PowerShell 删除子网站的方法:
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/Sales"
$SubsiteURL = "2018" # Just URL of the Subsite - NOT Relative Path
#Get Credentials to connect
$Cred = Get-Credential
#Connect PnP Online to Parent Web
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online delete subsite powershell
Remove-PnPWeb -Identity $SubsiteURL -Force
Remove-PnPWeb cmdlet 可永久删除特定子网站。但是,如果您的子网站有任何子子网站,脚本最终会出现错误:
Remove-PnPWeb:删除网站“/Sep”时出现问题。无法删除具有子网站或某些应用程序的网站。请删除所有子网站并删除应用程序后重试。
当您尝试使用网络浏览器删除包含子网站的网站时,您会收到类似的消息:
如何使用 PnP PowerShell 删除站点及其所有子站点?
作为 SharePoint 管理员,您可能需要删除网站集中的所有子网站。我们将演示如何使用 PowerShell 删除 SharePoint Online 中的所有子网站。如果您需要清理网站结构或者从头开始并想要删除任何现有的子网站,这是一个方便的技巧。让我们删除 SharePoint Online 中给定网站(或子网站)下的所有一级子网站:
#Subsite URL
$SiteURL = "https://crescent.sharepoint.com/sites/BoardPapers/September2020"
#Connect to subsite
Connect-PnPOnline -Url $SiteURL -Interactive
#Get all subsites and remove them
Get-PnPSubWebs | Remove-PnPWeb -Force
删除所有级别的所有子站点怎么样?以下是用于在 SharePoint Online 中递归删除所有子网站的 PnP PowerShell:
#Function to delete a subsite and its all child sites
Function Remove-PnPAllWebs([Microsoft.SharePoint.Client.Web]$Web)
{
#Get All Subsites of the web
$SubWebs = Get-PnPSubWeb -Identity $Web
ForEach($SubWeb in $SubWebs)
{
#Call the function recursively to remove subsites
Remove-PnPAllWebs($SubWeb)
}
#Delete the subsite
Remove-PnPWeb -Identity $Web -Force
Write-host -f Green "Deleted Sub-Site:"$Web.URL
}
#Config Variables
$SiteURL = "https://Crescent.sharepoint.com/sales"
#Get Credentials to connect
$Cred = Get-Credential
#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Get the Web
$Web = Get-PnPWeb
#sharepoint online powershell delete all subsites
Remove-PnPAllWebs $Web
若要删除 SharePoint Online 网站集,您可以使用 Microsoft 365 中的 SharePoint Online 管理中心或 PowerShell:如何删除 SharePoint Online 网站集?
经常问的问题:
如何在 SharePoint Online 中禁用子网站创建?
要在 SharePoint Online 网站中禁用子网站创建,请执行以下操作:登录 SharePoint 管理中心 >> 单击“设置”>>“经典设置”>> 在“子网站创建”部分下,将“隐藏子网站命令”设置为“关闭 SharePoint 子网站创建”所有网站,然后单击页面底部的“保存”按钮以提交更改。
详细信息:在 SharePoint Online 中禁用子网站创建
如何在 SharePoint Online 中创建现代子网站?
要在 SharePoint Online 中添加子网站,请按照下列步骤操作:
登录到您的 SharePoint Online 网站 >> 单击“网站设置”齿轮图标 >> 选择“网站内容”。在工具栏上,单击“新建”,然后单击“子站点”链接(URL 快捷方式:/_layouts/15/newsbweb.aspx)。提供新子网站的名称、描述、URL 和模板。指定其他可选设置,例如权限和导航。单击页面底部的“创建”按钮,在 SharePoint Online 中创建子网站。
详细信息:在 SharePoint Online 中添加子网站
如何在 SharePoint Online 中恢复已删除的子网站?
要恢复子网站: 以网站集管理员身份登录 SharePoint Online 网站集,导航到网站设置 >> 单击网站集管理下的“回收站” >> 单击“第二阶段回收站” >> 选择已删除的子网站然后单击“恢复”按钮恢复子站点。您也可以使用 PowerShell。
详细信息:SharePoint Online:使用 PowerShell 从回收站恢复已删除的子网站
已删除的 SharePoint 网站可以在回收站中保留多长时间?
使用 SharePoint Online 93 天!
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag