[玩转系统] SharePoint Online:用于获取所有网站集和子网站的 PowerShell
作者:精品下载站 日期:2024-12-14 14:35:11 浏览:14 分类:玩电脑
SharePoint Online:用于获取所有网站集和子网站的 PowerShell
要求: SharePoint Online PowerShell 获取所有网站集和子网站。
用于列出所有网站集和子网站的 SharePoint Online PowerShell
您是否需要获取 SharePoint Online 环境中所有网站和子网站的列表?手动检索 SharePoint Online 中所有网站和子网站的列表可能是一个耗时且容易出错的过程,尤其是当您拥有包含许多网站和子网站的大型 SharePoint 环境时。 PowerShell 让一切变得简单!使用 PowerShell,您可以快速轻松地检索 SharePoint Online 中所有网站和子网站的完整列表。
在本文中,我们将了解如何使用 PowerShell 从 SharePoint Online 租户获取 SharePoint Online 中的所有网站集和子网站。以下是用于列出 SharePoint Online 中所有网站和子网站的 CSOM PowerShell:
Import-Module Microsoft.Online.SharePoint.Powershell
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
#Function to get all subsites of a site
Function Get-SPOWeb($WebURL)
{
#Setup credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get Web information and subsites
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$Context.Credentials = $Credentials
$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)
{
#Get the web object
$Subweb
#Call the function recursively to process all subsites underneath the current web
Get-SPOWeb($Subweb.url)
}
}
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred
#Get All site collections
$SiteCollections = Get-SPOSite -Limit All
#Traverse through each site collection and get their subsits
Foreach ($Site in $SiteCollections)
{
Write-Host $Site.Url
$AllWebs = Get-SPOWeb $Site.Url
$AllWebs | ForEach-Object { Write-Host $_.URL }
}
这将为您提供网站集及其子网站的列表。这是另一个脚本:
SharePoint Online:PowerShell 列出所有网站集中的所有子网站
让我们从租户的所有网站集中获取子网站。以下是用于获取 SharePoint Online 中所有网站集和子网站的 PowerShell 脚本:
#Load SharePoint CSOM 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"
#Function to get each subsite in site collection
Function Get-SPOWebs($SiteURL)
{
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.Load($Web.Webs)
$Ctx.ExecuteQuery()
#Do something
Write-host $Web.Url
#Loop through each each subsite in site
Foreach($Web in $web.Webs)
{
Get-SPOWebs $Web.Url
}
}
#Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
#Setup Credentials to connect
$Cred= Get-Credential
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential ($Cred)
#Get all Site collections
$Sites = Get-SPOSite -Limit All
#Loop through site collections
ForEach($Site in $Sites)
{
#Call the function to get all sub-sites in site collection
Get-SPOWebs($Site.URL)
}
SharePoint 管理员可以使用此 PowerShell 快速获取租户中所有网站和子网站的列表。
PnP PowerShell 获取 SharePoint Online 中的所有网站和子网站
让我们看看如何使用 PnP PowerShell 模块获取 SharePoint Online 中的所有网站和子网站。此脚本使用 PnP PowerShell 递归地检索所有网站集及其子网站。
#Set Variables
$SiteURL = "https://crescent.sharepoint.com"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Get All Site collections
$SitesCollection = Get-PnPTenantSite
#Loop through each site collection
ForEach($Site in $SitesCollection)
{
Write-host -F Green $Site.Url
Try {
#Connect to site collection
Connect-PnPOnline -Url $Site.Url -Credentials $Cred
#Get Sub Sites Of the site collections
$SubSites = Get-PnPSubWeb -Recurse
ForEach ($web in $SubSites)
{
Write-host `t $Web.URL
}
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
此脚本使用 PnP PowerShell 获取 SharePoint Online 中的所有网站和子网站。
在执行此脚本之前,请确保您对租户中的所有网站集具有网站集管理员权限。否则,您可能会收到“远程服务器返回错误:(401) 未经授权。”错误! PowerShell 将网站集管理员添加到 SharePoint Online 中的所有网站获取 SharePoint Online 中每个网站集中的子网站计数:
在另一种情况下,我们希望快速获取租户中每个网站集的子网站数量(递归总计)。
#Parameters
$TenantAdminURL = "https://Crescent-Admin.SharePoint.com"
#Connect to Admin Center
$Cred = Get-Credential
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
#Get All Site collections - Exclude: Seach Center, Redirect site, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SitesCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0","REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
#Loop through each SharePoint site collection
$SubSitesData = @()
ForEach($Site in $SitesCollections)
{
#Connect to site collection
Write-host -f Yellow "Processing site:"$Site.Url
Connect-PnPOnline -Url $Site.Url -Credentials $Cred
#Get the SubSites of the site collection
$Webs = Get-PnPSubWeb -Recurse
#Collect Subsites count
$SubSitesData += New-Object PSObject -Property ([ordered]@{
SiteName = $Site.Title
URL = $Site.URL
SubSitesCount = $Webs.Length
})
}
$SubSitesData
将所有网站和子网站的列表导出到 CSV
如何在 PowerShell 中获取所有 SharePoint 网站和子网站?以下是 PnP PowerShell cmdlet Get-PnPTenantSite 和 Get-PnPSubWeb,用于获取租户中的所有网站集和子网站并将其导出到 CSV 文件。
#Set Variables
$TenantURL = "https://crescent.sharepoint.com"
$ExportFile = "C:\Temp\SitesandSubsites.csv"
$AllSitesList = @()
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $TenantURL -Interactive
#Get All Site collections - Exclude certain site templates such as personal sites
$SiteCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0","REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
Write-host "Total Number of site collections:"$SiteCollections.count
#Loop through each site collection
ForEach($Site in $SitesCollections)
{
#Connect to site collection
Connect-PnPOnline -Url $Site.Url -Interactive
#Get all Top-level site and Sub Sitess Of the SharePoint Online site collection
Get-PnPSubWeb -Recurse -IncludeRootWeb -Includes ParentWeb | ForEach-Object {
$AllSitesList += New-Object PSObject -property $([ordered]@{
SiteName = $_.Title
SiteURL = $_.Url
IsSubSite = If($_.ParentWeb.Title -eq $null) {$False} Else {$True}
})
}
}
}
Catch {
Write-host -f Red "Error:" $_.Exception.Message
}
#get all sites and subsites in sharepoint online
$AllSitesList
#Export All sites and Subsites list to a CSV list
$AllSitesList | Export-CSV -Path $ExportFile -NoTypeInformation -Encoding UTF8
总之,我们讨论了如何使用 PowerShell 获取 SharePoint 中的所有网站和子网站。使用本指南中的脚本,您可以快速轻松地检索 SharePoint Online 环境中的所有网站和子网站的列表。
经常问的问题:
如何在 SharePoint Online 中启用子网站?
要在 SharePoint Online 中启用子网站,请登录 SharePoint Online 管理中心 >> 单击“设置”>> 单击“经典设置页面”链接。在设置页面的“子网站创建”部分下,将选项设置为“为所有网站启用子网站创建”。
详细信息:在 SharePoint Online 中启用子网站
在 SharePoint Online 中可以创建多少个子网站?
每个网站集有 2,000 个子网站!但是,拥有大量子网站可能会对 SharePoint 环境的性能和可管理性产生影响!
如何授予 SharePoint Online 中子网站的权限?
假设您有一个具有唯一权限的子网站,请按照以下步骤授予对子网站的访问权限:
1.导航到您想要授予子网站权限的 SharePoint Online 网站。
2.单击页面右上角的齿轮图标,然后选择“站点设置”。
3.在“用户和权限”部分下,单击“站点权限”。
4.单击页面顶部功能区中的“授予权限”。
5.输入您想要授予权限的子网站用户或组的电子邮件地址或组名称。
6.选择您想要授予子网站用户或组的权限级别。可用的权限级别包括完全控制、设计、编辑、贡献、读取和有限访问。
7.单击“共享”向子网站用户或组授予权限。
子网站用户或组将收到一封电子邮件通知,其中包含子网站的链接。他们需要单击链接并使用其 Microsoft 帐户登录才能访问子网站。
相关文章:
- 如何使用 PowerShell 获取 SharePoint Online 中的所有网站集?
- SharePoint Online:使用 PowerShell 获取所有子网站
- SharePoint Online:如何使用 PowerShell 创建子网站?
猜你还喜欢
- 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