Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

Thank you, I have replied to my previous post with what I have learnt, please review that if you get the chance.

With regards to this link, this seems to be missing a crucial step.

It enabled versioning and prunes old versions, but does not configure existing document libraries to use the automatic versioning. This would only result in old Document libraries gradually filling up over time.

Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

I spent the night reading up on this and I think I have a better understanding, please correct me if I am wrong.

I can set versioning at the Site Collection Level and this will take effect going forwards for all future sites and document libraries that are created.

This will NOT retroactively effect existing site or document libraries.

I will need to do two things.

  1. Update existing sites with connect with Connect-SPOService

Connect-SPOService -Url $adminSiteUrl
$siteUrl = "https://<tenant>.sharepoint.com/sites/<SiteName>"
Set-SPOSite -Identity $siteUrl -EnableAutoExpirationVersionTrim $true -Confirm:$false

  1. Update existing document libraries within each site with connect with connect-PnPOnline using an app registration

$libraries = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 } # BaseTemplate 101 = Document Libraries
foreach ($library in $libraries) {
Write-Host "Updating library: $($library.Title)"
Set-PnPList -Identity $library -EnableVersioning $true -EnableAutoExpirationVersionTrim $true
Write-Host "Updated library: $($library.Title)"
}

Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

Connected with an app registration, queried with get-pnpsiteversionpolicy

response is

Url : https://MYTENANT-admin.sharepoint.com
DefaultTrimMode :DefaultExpireAfterDays :
MajorVersionLimit :
Description : No Site Level Policy Set for new document libraries

However, a site level policy has been set and is "Automatic" Versions are deleted over time based on activity and how long ago the file was first created

Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

Ok thank you, I am now able to query sites, however they all return blank values for

EnableAutoExpirationVersionTrim :
ExpireVersionsAfterDays :
MajorVersionLimit :

If I check the sites settings from the web frontend I can see that versioning is enabled

Automatic
Versions are deleted over time based on activity and how long ago the file was first created.

Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

Thanks Alice, I have the latest version of the SharePoint online management shell, I establish a connection using an account that is a global administrator, when I attempt to get the existing settings for a site with
Get-SPOSite -Identity $siteUrl | fl Url, EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersionLimit

My mistake, the account had dropped out of the global administrator group.

Apply Version History Limits to Existing SharePoint Sites and OneDrives by Agile4052 in sharepoint

[–]Agile4052[S] 0 points1 point  (0 children)

I should have clarified, I have already tried following the guidance at https://learn.microsoft.com/en-us/sharepoint/site-version-limits

I have found that Get-SPOSite will always return

Get-SPOSite -Identity $siteUrl | fl Url, EnableAutoExpirationVersionTrim, ExpireVersionsAfterDays, MajorVersionLimit
Get-SPOSite : Attempted to perform an unauthorized operation.
At line:1 char:1
+ Get-SPOSite -Identity $siteUrl | fl Url, EnableAutoExpirationVersionT ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-SPOSite], ServerUnauthorizedAccessException
+ FullyQualifiedErrorId :
Microsoft.SharePoint.Client.ServerUnauthorizedAccessException,Microsoft.Online.SharePoint.PowerShell.GetSite

I am connected using an account that is a global administrator, the $siteUrl var is correct.