This PowerShell script imports Sharepoint Online URLs from a CSV, and sets versioning limits on all document libraries in each site in the CSV.
<#
Set Version limits for all Doc Libraries in SharePoint Online Sites lised in a CSV
Author: Tom DeMeulenaere - Jan 4, 2023
Source:
https://www.sharepointdiary.com/2016/05/sharepoint-online-enable-versioning-on-all-lists-powershell.html
#>
$sitelist = Import-CSV C:\SWSetup\SharepointSites.csv
$SPAdminURL = "https://contoso-admin.sharepoint.com"
Connect-PnPOnline -Url $SPAdminURL -Interactive
#Exclude
certain libraries
$ExcludedLists = ("Preservation Hold Library","Site Assets","Site Pages","Style Library","Form Templates")
Function Enable-PnPVersionHistory($SiteURL)
{
Write-host "Processing Web $($_.URL)" -f Cyan
Connect-PnPOnline -Url $SiteURL -Interactive
#Get All Document Libraries
$Lists = Get-PnPList | Where-Object {$_.Hidden -eq $False -and $_.BaseType -eq "DocumentLibrary" -and $ExcludedLists -notcontains $_.Title}
#Enable Version History for Document Libraries
$Lists | ForEach-Object {
$Params = @{
"Identity" = $_.Title
"EnableVersioning" = $True
"MajorVersions" = 50
"MinorVersions" = 10
}
Set-PnPList @Params
Write-host "Enabled Version History for "$_.Title -f Green
}
}
foreach ($s in $sitelist)
{
#Connect to SharePoint Online Site from PnP Online
Connect-PnPOnline -Url $s.URL -Interactive
$start = Get-Date
#Get all Webs and call the function to set version history
Get-PnPSubWeb -IncludeRootWeb | ForEach-Object { Enable-PnPVersionHistory $s.URL }
Write-host "Completed setting versioning for "$s.URL" Time Elapsed: "(New-TimeSpan -Start $start -End (Get-Date)) -f Yellow
}
Set Version limits for all Doc Libraries in SharePoint Online Sites lised in a CSV
Author: Tom DeMeulenaere - Jan 4, 2023
#>
$SPAdminURL = "https://contoso-admin.sharepoint.com"
Connect-PnPOnline -Url $SPAdminURL -Interactive
$ExcludedLists = ("Preservation Hold Library","Site Assets","Site Pages","Style Library","Form Templates")
{
Write-host "Processing Web $($_.URL)" -f Cyan
Connect-PnPOnline -Url $SiteURL -Interactive
#Get All Document Libraries
$Lists = Get-PnPList | Where-Object {$_.Hidden -eq $False -and $_.BaseType -eq "DocumentLibrary" -and $ExcludedLists -notcontains $_.Title}
#Enable Version History for Document Libraries
$Lists | ForEach-Object {
$Params = @{
"Identity" = $_.Title
"EnableVersioning" = $True
"MajorVersions" = 50
"MinorVersions" = 10
}
Set-PnPList @Params
Write-host "Enabled Version History for "$_.Title -f Green
}
}
{
#Connect to SharePoint Online Site from PnP Online
Connect-PnPOnline -Url $s.URL -Interactive
$start = Get-Date
#Get all Webs and call the function to set version history
Get-PnPSubWeb -IncludeRootWeb | ForEach-Object { Enable-PnPVersionHistory $s.URL }
Write-host "Completed setting versioning for "$s.URL" Time Elapsed: "(New-TimeSpan -Start $start -End (Get-Date)) -f Yellow
}
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.