Forum Discussion
Total Size of Preservation Hold Libraries
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
}
Thanks for this. I've tried it but am new to PnP. Installed and registered Pnp and SPO modules in Powershell.
I saved your script as a ps1 file.
But when I run the script it appears to just finish with no output. I tried to run it line by line or section by section and all I can basically see/verify is
"$sites = Get-SPOSite -Limit All" does indeed get the list of sites.
That's about all I can see/verify.
I do have another general question.... We have around 9,000 SharePoint sites in our organisation (I know!!! Shock!) This script won't prompt me to log into each and every site will it? I am assuming it'll just prompt me once and then run through each site hopefully....
Any guidance would really be appreciated.
- Anonymous_TechMar 14, 2024Copper Contributor
a bit late to this but you only have to do it once on one random site before you go through the loop
$connection = connect-pnponline -url $url -Interactive -ReturnConnectionThis stores the current o365 authentication session in $connection, you can then use that connection to authenticate to sharepoint when you reiterate each siteconnect-pnponline -url $url -interactive -ClientId $connection.clientid -Connection $connection - AmitV1840Aug 28, 2023Copper Contributor
Hello DesShiels
I am also looking for script for same reason. I want to extract size of Preserve hold Lib for all sites.
I am already using /_layouts/15/storman.aspx however I have more than 2 K sites and it getitng very hectic to check.
If you already found the solution, please help me as well