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

[玩转系统] 使用 PowerShell 获取 SharePoint 页面布局使用情况分析报告

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

使用 PowerShell 获取 SharePoint 页面布局使用情况分析报告


要求:获取所有可用页面布局及其在 SharePoint 网站集中的使用情况的清单。

如何获取SharePoint中的所有页面布局?

SharePoint 提供了页面布局功能,允许站点管理员创建和管理可重用的页面模板。当您需要在网站上快速创建新页面或想要在页面之间保持一致的外观时,这会很有帮助。但是,确定哪些页面正在使用哪些布局可能很困难,尤其是当您的网站有很多页面时。这篇博文将向您展示如何使用 PowerShell 生成一份报告,其中列出了您网站上的所有页面及其相应的布局使用情况。

如果进入“网站设置”页面,您可以在“页面布局和网站模板”或“母版页和页面布局”链接下找到页面布局。

[玩转系统] 使用 PowerShell 获取 SharePoint 页面布局使用情况分析报告

获取发布网站集的所有可用页面布局

SharePoint 页面布局的范围仅限于网站集级别。让我们获取站点的所有页面布局:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Get-PageLayouts
{
    param
    (
        [Parameter(Mandatory=$true)][Microsoft.SharePoint.SPSite]$Site
    )
    
    #Get the Publishing Site object
    [Microsoft.Sharepoint.Publishing.PublishingSite]$PublishingSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Site)
    
    #Get All page layouts  
    $PageLayouts = $PublishingSite.GetPageLayouts($false)
        
    ForEach($PageLayout in $PageLayouts)
    {
            Write-host $PageLayout.Name : $PageLayout.ServerRelativeUrl
    }
}

#Get a Site collection
$Site = Get-SPSite "https://Opera.crescent.com/"

#Call the function to get all available page layouts
Get-PageLayouts -Site $Site

使用 PowerShell 获取 SharePoint 网站集中的页面布局使用情况:

现在,让我们审核特定网站集中的页面布局使用情况:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Get-PageLayoutsUsage
{
    param
    (
        [Parameter(Mandatory=$true)][Microsoft.SharePoint.SPSite]$Site,
        [Parameter(Mandatory=$true)][String]$ReportFile
    )
    
    #Array to store Result
    $ResultSet = @()
 
    #Iterate through each web of the site collection
    ForEach($web in $Site.AllWebs)
    {
        Write-host -f Cyan "Scanning site $($Web.URL)..."
        $PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)
        
        if($PublishingWeb.PagesList)
        {
            foreach($Page in $PublishingWeb.GetPublishingPages())
            {
                #Get the page layout details    
                $Result = new-object PSObject
                $Result | add-member -membertype NoteProperty -name "URL" -Value $web.Url
                $Result | add-member -membertype NoteProperty -name "Page URL" -Value $Page.Uri.ToString()
                $Result | add-member -membertype NoteProperty -name "PageLayout URL" -Value $Page.Layout.ServerRelativeUrl
                $Result | add-member -membertype NoteProperty -name "PageLayout Name" -Value $Page.Layout.Name

                $ResultSet += $Result
            }            
        }
    }
    #Export Result to csv file
    $ResultSet |  Export-Csv $ReportFile -notypeinformation
    
    Write-Host "Page Layouts Usage Report Generated Successfully!" -f Green
}

#Get a Site collection
$Site = Get-SPSite "https://portal.crescent.com/"
$ReportFile="C:\Temp\PageLayouts.csv"

#Call the function to get page layouts usage
Get-PageLayoutsUsage -Site $Site -ReportFile $ReportFile

该脚本生成以下格式的 CSV 文件:

[玩转系统] 使用 PowerShell 获取 SharePoint 页面布局使用情况分析报告

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

取消回复欢迎 发表评论:

关灯