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

[玩转系统] 使用 PowerShell 获取 SharePoint 网站集的所有列表和库清单

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

使用 PowerShell 获取 SharePoint 网站集的所有列表和库清单


要求:获取 SharePoint 网站集的所有列表和库清单。

PowerShell 获取网站集列表和库库存:

如果您需要获得 SharePoint 网站中所有列表和库的全面清单,PowerShell 就是您的最佳选择!在这篇博文中,我们将了解如何使用 PowerShell 获取 SharePoint 网站的列表和库清单。我们还将了解如何获取 Web 应用程序中每个网站集可用的所有内容的详细列表。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection Variable
$SiteURL="https://intranet.crescent.com"
$ReportOutput="C:\SiteInventory.csv"

#Get the site collection
$Site = Get-SPSite $SiteURL

$ResultData = @()
#Ge All Sites of the Site collection
Foreach($web in $Site.AllWebs)
{
    Write-host -f Yellow "Processing Site: "$Web.URL
 
    #Get all lists - Exclude Hidden System lists
    $ListCollection = $web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false)}

    #Iterate through All lists and Libraries
    ForEach ($List in $ListCollection)
    {
            $ResultData+= New-Object PSObject -Property @{
            'Site Title' = $Web.Title
            'Site URL' = $Web.URL
            'List-Library Name' = $List.Title
            'Item Count' = $List.ItemCount
            'Created By' = $List.Author.DisplayName
            'Last Modified' = $List.LastItemModifiedDate.ToString();
            'List URL' = "$($Web.Url)/$($List.RootFolder.Url)"
            } 
    } 
}

#Export the data to CSV
$ResultData | Export-Csv $ReportOutput -NoTypeInformation

Write-host -f Green "Report Generated Successfully at : "$ReportOutput

此脚本将结果导出到 CSV 文件以供进一步分析,这有助于排除故障或审核目的。

报告输出:

[玩转系统] 使用 PowerShell 获取 SharePoint 网站集的所有列表和库清单

获取 Web 应用程序中所有网站集的列表和库清单

在运行脚本之前,请确保添加对 Web 应用程序具有完全控制权的 Web 应用程序用户策略。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Parameters
$WebAppURL="https://intranet.sharepoint.com"
$ReportOutput="C:\Temp\SiteInventory.csv"

#Delete the Output report file if exists
If (Test-Path $ReportOutput) { Remove-Item $ReportOutput }
 
#Get all site collections from the web application
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL -PipelineVariable Web | ForEach-Object {
    Write-host -f Yellow "Processing Site: "$Web.URL
  
    #Get all lists - Exclude Hidden System lists
    $ListCollection = $Web.lists | Where-Object  { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false)}
    
    $ResultData = @()
    #Iterate through All lists and Libraries
    ForEach ($List in $ListCollection)
    {
            $ResultData+= New-Object PSObject -Property @{
            'Site Title' = $Web.Title
            'Site URL' = $Web.URL
            'List/Library Name' = $List.Title
            'Item Count' = $List.ItemCount
            'Created By' = $List.Author.DisplayName
            'Last Modified' = $List.LastItemModifiedDate.ToString();
            'List URL' = "$($Web.Url)/$($List.RootFolder.Url)"
            }
    }

    #Append data to CSV
    $ResultData | Export-Csv $ReportOutput -NoTypeInformation -Append
}
Write-host -f Green "Report Generated Successfully at: "$ReportOutput

检索 SharePoint 网站集中所有列表和库的清单是一项常见任务。通过 PowerShell,只需几个步骤即可轻松检索 SharePoint 网站集中所有列表和库的清单。使用本文中提供的脚本可以节省您的时间和精力!

如果要生成网站中所有文档的清单,请使用:使用 PowerShell 获取网站集的文档清单

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

取消回复欢迎 发表评论:

关灯