[玩转系统] SharePoint Online:使用 PowerShell 获取所有网站集
作者:精品下载站 日期:2024-12-14 14:12:06 浏览:14 分类:玩电脑
SharePoint Online:使用 PowerShell 获取所有网站集
要求:在 SharePoint Online 中使用 PowerShell 获取所有网站集。
如何获取 SharePoint Online 中的网站集列表?
网站集是一组网站,通常按部门、项目、区域、职能或业务单位组织。如果您负责管理 SharePoint Online 环境,您迟早需要获取租户中所有网站集的列表。值得庆幸的是,PowerShell 使收集有关 SharePoint Online 环境的信息变得容易。本博文将向您展示如何使用 PowerShell 获取租户中所有网站集的列表。您还将了解如何将结果导出到 CSV 或 HTML 文件以用于报告目的。
使用 SharePoint 管理中心查看 SharePoint Online 租户中的所有网站
如何查看SharePoint Online中的所有网站集?那么,如果您想获取 SharePoint Online 网站集的列表,您可以转到 SharePoint 管理中心 (https://YourDomain-admin.sharepoint.com) >> 展开“网站”> > 活跃站点。
这将为您提供 SharePoint Online 中所有网站集的列表。您可以通过单击工具栏中的“导出”按钮将它们导出为 CSV。让我们看看如何使用 SharePoint Online PowerShell 获取所有网站集。
如何使用 PowerShell 在 SharePoint Online 中获取网站集?
作为 SharePoint Online 管理员,您需要检索有关 SharePoint 环境中特定网站集的信息。要使用 PowerShell 在 SharePoint Online 中获取网站集,您可以按照以下步骤操作:
- 在本地计算机上打开 PowerShell。
- 使用 Connect-SPOService cmdlet 连接到您的 SharePoint Online 租户。您将需要提供您的 SharePoint Online 管理 URL 和凭据。
- 运行 Get-SPOSite cmdlet 以检索所需的网站集。例如,要检索 URL 为“https://crescent.sharepoint.com/sites/marketing”的网站集,您可以运行以下命令:
Get-SPOSite -Identity https://crescent.sharepoint。 com/sites/marketing
这将返回有关网站集的信息,包括其 URL、标题和所有者。 - 如果要检索有关网站集的其他信息,可以使用其他 PowerShell cmdlet,例如 Get-SPOSiteGroup 或 Get-SPOSiteGroupPermissions。
#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to SharePoint Online from PowerShell
Connect-SPOService -url $AdminSiteURL
#Get the Site Collection
$Site = Get-SPOSite -Identity $SiteURL
#sharepoint online list all site collections powershell
$Site | Select -Property Template, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, sharingcapability
请注意,要运行 SharePoint Online 的 PowerShell cmdlet,您需要在租户上具有 SharePoint 管理员角色,并在本地计算机上安装 SharePoint Online Management Shell(或 SharePoint Online PowerShell 模块)。
如何使用 PowerShell 获取 SharePoint Online 中的所有网站集?
网站集是 SharePoint Online 中的主要对象。使用 Get-SPOSite PowerShell cmdlet 列出租户中的所有网站集。与本地SharePoint Management Shell类似,您还可以使用“SharePoint Online Management Shell”连接到Office 365和SharePoint Online网站!以下是用于获取 SharePoint Online 中所有网站集的 PowerShell 脚本:
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$Credential = Get-credential
Connect-SPOService -url $AdminSiteURL -Credential $Credential
#sharepoint online list all site collections powershell
Get-SPOSite -Limit All | Format-Table Url, Template, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, sharingcapability -AutoSize
默认情况下,Get-SPOSite cmdlet 检索 200 个网站集。我们必须将“Limit”开关指定为“All”,才能从租户获取所有站点。以下是 PowerShell 脚本,用于从 SharePoint Online 获取包含详细信息的所有网站集并将所有网站集库存导出到 CSV:
Connect-SPOService -url "https://crescent-admin.sharepoint.com" -Credential (Get-credential)
Get-SPOSite -Detailed | Export-CSV -LiteralPath C:\Temp\SitesInventory.csv -NoTypeInformation
此 PowerShell 列出了 SharePoint Online 租户中的所有网站集以及所有可用的网站集详细信息。
PowerShell 获取 SharePoint Online 中的所有网站集
使用保存的凭据连接到 SharePoint Online 怎么样?下面是使用保存的凭据列出所有 SharePoint Online 网站的 PowerShell(我假设您在脚本中指定的帐户未启用 MFA!):
#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
$AdminUrl = "https://crescent-admin.sharepoint.com/"
$UserName= "[email protected]"
$Password = "Password goes here"
#Setup Credentials to connect
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
#connect to the service
Connect-SPOService -Url $AdminUrl -Credential $Credentials
#sharepoint online get all site collections PowerShell
$SiteColl = Get-SPOSite
#sharepoint online PowerShell iterate through all site collections
ForEach($Site in $SiteColl)
{
Write-host $Site.Url
}
用于获取所有网站集的 PowerShell,包括现代团队网站和组网站:
此 PowerShell 枚举 SharePoint Online 中的网站集并获取每个网站的 URL。
让我们使用 PowerShell 获取所有网站的列表,包括 SharePoint Online 中的现代团队网站和组连接网站。
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
#Get All Site collections from the Tenant- Including Modern Team sites and communication sites
Function Get-SPOSites($AdminSiteURL, $Cred)
{
#Setup credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
$Ctx.Credentials = $Credentials
#Get the tenant object
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($ctx)
#Get All Site Collections
$SiteCollections=$Tenant.GetSitePropertiesFromSharePoint(0,$true)
$Ctx.Load($SiteCollections)
$Ctx.ExecuteQuery()
#Iterate through Each site collection
ForEach($Site in $SiteCollections)
{
Write-host $Site.URL
}
}
#Set Parameters
$AdminSiteUrl = "https://crescent-admin.sharepoint.com/"
$Cred= Get-Credential
#sharepoint online powershell list all sites
Get-SPOSites -AdminSiteURL $AdminSiteUrl -Cred $Cred
SharePoint Online PowerShell 列出所有网站集
让我们获取特定路径下的所有网站集:
Import-Module Microsoft.Online.SharePoint.Powershell
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
#Get Credentials to connect to the SharePoint Admin Center
$Cred = Get-Credential
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred
#Get All site collections which has /sites in its path
Get-SPOSite -Filter { Url -like '*/sites*' } -Limit All
#Get All site collections of Group site template
#Get-SPOSite -Filter { Template -eq "GROUP#0" } -Limit All
您可以根据某些条件过滤并获取所有网站集。例如,让我们获取所有使用 > 1 GB 存储的网站。
Get-SPOSite -Limit All | where { $_.StorageUsageCurrent -gt 1024 }
过滤和获取集合:例如,获取 URL 中包含“Project*”的所有网站集。
Get-SPOSite -Filter {$_.url -like "https://tenant.sharepoint.com/sites/Project*"}
SharePoint Online PnP PowerShell 获取所有网站
需要获取 SharePoint Online 环境中所有网站集的列表? PnP PowerShell 来救援!此脚本向您展示如何使用 PnP PowerShell cmdlet Get-PnPTenantSite 获取租户中所有网站集的列表。
#Set Parameter
$TenantSiteURL="https://crescent.sharepoint.com"
#Connect to the Tenant site
Connect-PnPOnline $TenantSiteURL -Credentials (Get-Credential)
#sharepoint online pnp powershell get all sites
Get-PnPTenantSite
我们可以使用以下命令提取所有网站集详细信息并将其导出为 CSV:
#Config Variables
$TenantSiteURL = "https://crescent-admin.sharepoint.com/"
$CSVFilePath = "C:\Temp\AllSitesData.csv"
#Connect to Tenant Admin Site
Connect-PnPOnline -Url $TenantSiteURL -Interactive
#Get All Site collections data and export to CSV
Get-PnPTenantSite -Detailed | Select Title, URL, Owner, LastContentModifiedDate, WebsCount, Template, StorageUsage | Export-Csv -path $CSVFilePath -NoTypeInformation
这将获取所有网站集,包括现代团队网站和通信网站。我们跳过搜索中心、我的网站主机、应用程序目录、内容类型中心、电子数据展示和机器人等,获取租户中所有网站的配额:
#Parameter
$TenantAdminURL = "https://Crescent-admin.sharepoint.com"
#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Interactive
#Get All Site collections - Exclude: Seach Center, Redirect site, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SiteCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
#Loop through each site collection
ForEach($Site in $SiteCollections)
{
#Get the storage Quota of the site
Write-host $Site.URL - $Site.StorageQuota
}
您可以将 OneDrive 站点包含为:
#Get all site collections including OneDrive Sites
Get-PnPTenantSite -IncludeOneDriveSites
获取 HTML 报告格式的网站集列表
让我们使用 PowerShell 以友好的 HTML 格式获取所有网站集的列表:
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking
#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SitesRpt.html"
#CSS Styles
$HeadTag = @"
<style type="text/css">
table {
border-collapse: collapse; font-family: verdana,arial,sans-serif;
font-size:11px; color:#333333; border-width: 1px; border-color: #a9c6c9;
border: b1a0c7 0.5pt solid; border-spacing: 1px; border-collapse: separate; /*Sal Table format */
}
th {
border-width: 1px; padding: 5px; background-color:#8064a2;
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt;
color: white; font-size: 11pt; font-weight: 700; text-decoration: none;
}
td {
border: #b1a0c7 0.5pt solid; font-family: Calibri; height: 15pt; color: black;
font-size: 11pt; font-weight: 400; text-decoration: none;
}
tr:nth-child(even) { background-color: #e4dfec; }
tr:hover { background-color: #694D8C; color:#ffffff }
</style>
"@
$PreContentTag = "<h3> SharePoint Online: Site Collections Inventory Report </h3>"
#Get Credentials to connect to the SharePoint Admin Center
$Cred = Get-Credential
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -Credential $Cred
#Get All site collections
$SiteCollections = Get-SPOSite -Limit All
Write-Host "Total Number of Site collections Found:"$SiteCollections.count -f Yellow
#Get the site collection details, convert to html and output to the report
$SiteCollections | ConvertTo-HTML -Title "Site Collection Inventory Report" -Property URL, Title,@{Expression={$_.LastContentModifiedDate }; Label="Last Modified"} -Head $HeadTag -PreContent $PreContentTag | Out-File $ReportOutput
报告如下所示:
包起来
总之,PowerShell 提供了一种强大而有效的方法来检索 SharePoint Online 中所有网站集的列表。通过使用适当的 PowerShell cmdlet,SharePoint 管理员可以快速轻松地检索其环境中所有网站集的完整列表。此信息可用于各种管理和审核任务,例如审核、故障排除、跟踪使用情况和优化 SharePoint 环境。
这是另一篇有关将 PowerShell 与 SharePoint Online 结合使用的文章:如何将 PowerShell 与 SharePoint Online 结合使用?
经常问的问题:
如何使用 PowerShell 创建 SharePoint Online 网站集?
您可以使用 SharePoint Online Management Shell - New-SPOSite、PnP PowerShell cmdlet New-PnPTenantSite 或 CSOM PowerShell 脚本在 SharePoint Online 中创建新网站。
详细信息:PowerShell 在 SharePoint Online 中创建新网站集
如何使用 PowerShell 获取 SharePoint Online 中的所有子网站?
若要从 SharePoint Online 网站获取所有子网站,请使用:PnP PowerShell 中的 Get-PnPSubWeb cmdlet。您还可以使用 CSOM PowerShell 脚本加载网站集的获取网站(子网站)。
详细信息:PowerShell 在 SharePoint Online 中获取网站集中的所有子网站
如何在 PowerShell 中获取所有 SharePoint 网站和子网站?
要获取所有网站集和子网站,您必须在 CSOM 中递归获取 Web 集合。使用 PnP PowerShell:Get-PnPSubWeb -Recurse
详细信息:PowerShell 获取 SharePoint Online 中的所有网站集和子网站
猜你还喜欢
- 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