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

[玩转系统] SharePoint Online:使用 PowerShell 审核所有列表和库的版本控制设置

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

SharePoint Online:使用 PowerShell 审核所有列表和库的版本控制设置


要求:审核 SharePoint Online 网站集中所有列表和库的版本控制设置。

[玩转系统] SharePoint Online:使用 PowerShell 审核所有列表和库的版本控制设置

PowerShell 为 SharePoint Online 网站集生成版本控制设置分析:

正在寻找一种方法来审核 SharePoint Online 环境中所有列表和库的版本控制? PowerShell 可以提供帮助!在本文中,我们将介绍 PowerShell 脚本,该脚本允许您分析 SharePoint Online 网站中所有列表和库的版本控制设置。

让我们审核给定网站集的所有列表和库的版本控制设置。


#Import SharePoint Online module
Import-Module Microsoft.Online.SharePoint.Powershell

Function Audit-VersioningSettings()
{
  param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ReportOutput
    )
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        
        #Get all subsites and Lists from the site
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)  
        $Lists = $Web.Lists
        $Ctx.Load($Lists)        
        $Ctx.ExecuteQuery()
        
        $VersioningData = @()
        Write-host -f Yellow "Processing Site: "$SiteURL
        #Iterate through each list in a site and get versioning configuration
        ForEach($List in $Lists)
        {
            $VersioningData += New-Object PSObject -Property @{
            'Site' = $SiteURL
            'List' = $List.Title
            'Versioning Enabled' = $List.EnableVersioning
            'Major Versions Limit' = $List.MajorVersionLimit
            'Draft Versions Limit' = $List.MajorWithMinorVersionsLimit
            'Draft Item Security' = $List.DraftVersionVisibility
            'Content Approval Required' = $List.EnableModeration
            'Checkout Required' = $List.ForceCheckout
            }
        }
        #Export the data to CSV
        $VersioningData | Export-Csv $ReportOutput -Append -NoTypeInformation

        #Iterate through each subsite in the current web
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function recursively to process all subsites underneaththe current web
            Audit-VersioningSettings -SiteURL $Subweb.URL -ReportOutput $ReportOutput
        }
     }
    Catch {
        write-host -f Red "Error Auditing versioning Settings!" $_.Exception.Message
    } 
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ReportOutput="C:\Temp\VersioningData.csv"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Delete the Output report file if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }

#Call the function to generate versioning data audit report
Audit-VersioningSettings -SiteURL $SiteURL -ReportOutput $ReportOutput

此 PowerShell 脚本生成 $ReportOutput 参数中提供的 CSV 输出。

[玩转系统] SharePoint Online:使用 PowerShell 审核所有列表和库的版本控制设置

请注意,此脚本获取给定网站集的版本控制配置。您可以检索所有网站集、循环并调用该函数以获取 SharePoint Online 中所有网站集的版本历史记录分析。

如何排除系统列表和库?

好吧,上面的脚本扫描所有列表和库,包括系统列表。这是排除所有系统列表的更改(您可以添加任何缺失的!)


#Exclude system lists
$ExcludedLists = @("Access Requests","App Packages","appdata","appfiles","Apps in Testing","Cache Profiles","Composed Looks","Content and Structure Reports","Content type publishing error log","Converted Forms", "Device Channels","Form Templates","fpdatasources","Get started with Apps for Office and SharePoint","List Template Gallery", "Long Running Operation Status","Maintenance Log Library"            ,"Master Docs","Master Page Gallery","MicroFeed","NintexFormXml","Quick Deploy Items","Relationships List","Reusable Content","Reporting Metadata", "Reporting Templates", "Search Config List","Site Assets","Site Pages", "Solution Gallery","Style Library","Suggested Content Browser Locations","Theme Gallery", "TaxonomyHiddenList","User Information List","Web Part Gallery","wfpub","wfsvc","Workflow History","Workflow Tasks")

$VersioningData = @()
Write-host -f Yellow "Processing Site: "$SiteURL
#Iterate through each list in a site and get versioning configuration
ForEach($List in $Lists)
{
    if($ExcludedLists -NotContains $List.Title -and $List.Hidden -eq $False)
    {
        $VersioningData += New-Object PSObject -Property @{
        'Site' = $SiteURL
        'List' = $List.Title
        'Versioning Enabled' = $List.EnableVersioning
        'Major Versions Limit' = $List.MajorVersionLimit
        'Draft Versions Limit' = $List.MajorWithMinorVersionsLimit
        'Draft Item Security' = $List.DraftVersionVisibility
        'Content Approval Required' = $List.EnableModeration
        'Checkout Required' = $List.ForceCheckout
        }
    }
}

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

取消回复欢迎 发表评论:

关灯