当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 获取 Web 应用程序中的所有 SharePoint 网站集

作者:精品下载站 日期:2024-12-14 14:21:21 浏览:13 分类:玩电脑

使用 PowerShell 获取 Web 应用程序中的所有 SharePoint 网站集


如何在 SharePoint 中获取 Web 应用程序的所有网站集?

Web 应用程序中的所有网站集和网站共享相同的顶级 URL。要从 SharePoint 中央管理获取 Web 应用程序中的所有网站集,请执行以下步骤:

  1. 转到 SharePoint 中心管理站点 >> 应用程序管理。
  2. 单击网站集组下的“查看所有网站集”链接。选择您的网络应用程序。此页面列出了所选 Web 应用程序中的所有网站集。

    [玩转系统] 使用 PowerShell 获取 Web 应用程序中的所有 SharePoint 网站集

使用 PowerShell 获取 Web 应用程序中的所有网站集:

下面是用于列出 Web 应用程序中所有网站集的 PowerShell。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set the Web application URL
$WebAppURL="https://intranet.crescent.com"

#Get the Web Application        
$WebApp = Get-SPWebApplication $WebAppURL

#Get all Site collections from the web application
$SitesCollection  = $WebApp.Sites

#Enumerate all site collections in the web application
Foreach($Site in $SitesCollection)
{
    #Get Site Collection URL, Owner, Content Database Details
    Write-host $Site.URL
}

虽然以上代码是按传统方式编写的,但您可以使用 PowerShell 单行代码来获取 Web 应用程序中所有网站集的列表:


Get-SPWebApplication "https://intranet.crescent.com" | Get-SPSite | Select URL

使用 PowerShell 获取 Web 应用程序中的所有网站集:

这次,让我们使用 PowerShell 表达式来深入研究网站集属性,例如:网站名称、内容数据库等。


Get-SPWebApplication "https://intranet.crescent.com" | Get-SPSite -Limit All | Select URL,@{Name="Site Name"; Expression={$_.RootWeb.Title}},Owner 

如何获取 Web 应用程序中的所有网站集并将其导出为 CSV

如何使用 PowerShell 获取 Web 应用程序中的所有网站集并导出为 CSV?


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Web application URL and CSV File location Variables
$WebAppURL="https://intranet.crescent.com"
$CSVFile="C:\SitesList.csv"

#Get list of site collections in a web application powershell
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All | ForEach-Object {
    New-Object -TypeName PSObject -Property @{
             SiteName = $_.RootWeb.Title
             Url = $_.Url
             DatabaseName = $_.ContentDatabase.Name }
} | Export-CSV $CSVFile -NoTypeInformation

此脚本从给定的 Web 应用程序获取所有网站集并将数据导出到 CSV。

[玩转系统] 使用 PowerShell 获取 Web 应用程序中的所有 SharePoint 网站集

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯