Forum Discussion
Amrah_Chughtai
May 31, 2021Copper Contributor
Total Size of Preservation Hold Libraries
Hello All, I am wondering if someone can help with a PowerShell script to retrieve the size of Preservation hold libraries in all the SharePoint Sites and OneDrive. I need to calculate the total...
Technut
Oct 27, 2021Copper Contributor
Amrah_Chughtai This may be a bit late but here's something I wrote that should point you in the correct direction.
The below PowerShell script requires modules for SharePoint Online Powershell and SharePoint PnP to be available on the machine.
Known issues:
- The script does not process sub-sites, this can probably be easily fixed.
- The "Measure-PNPList" cmdlet fails if the number of items in the preservation hold library exceeds the list view limit. The limit can be changed on the target sites, not sure if it can be done using PowerShell.
Hope this helps and perhaps someone else will improve and share a new version of the script 🙂
$Out = @()
$sites = Get-SPOSite -Limit ALL
$Sites = $Sites | Sort-Object StorageUsageCurrent -Descending
foreach ($Site in $Sites){
Connect-PnPOnline -Url $site.Url -Interactive
$SiteSize = $Site.StorageUsageCurrent
$PHLib = Get-PnPList -Identity PreservationHoldLibrary
if($PHLib){
$PHSize = ($PHLib | Measure-PnPList).TotalFileSize
$PHSize = $PHSize / 1024 / 1024
}
else {continue}
if(!$PHSize){continue}
$item = New-Object PSObject
$item | Add-Member -type NoteProperty -Name 'Url' -Value $site.Url
$item | Add-Member -type NoteProperty -Name 'SiteSizeMB' -Value $SiteSize
$item | Add-Member -type NoteProperty -Name 'PreservationSizeMB' -Value ([math]::Round($PHSize))
$item | Add-Member -type NoteProperty -Name 'PreservationPercentage' -Value ([math]::Round((($PHSize/$SiteSize)*100)))
$item
$out +=$item
}
KyleOliq
Sep 26, 2024Copper Contributor
Technut did anyone find a way around the list view threshold limit?
- BarbarurSep 26, 2024Brass ContributorYou can use this sample script using PnP: https://github.com/Barbarur/NovaPointPowerShell/tree/main/Solutions
The Preservation Hold Library is a list/library therefore is on the same page to get list and libraries.
Alternative, you can use this Free and open-source app to get a report of the Preservation Hold Library: https://github.com/Barbarur/NovaPoint