May 31 2021 01:53 PM
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 space being used by items in Preservation Hold Libraries in our tenant. Thanks so much for the help in advance.
Oct 27 2021 02:08 AM
@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:
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
}
Jul 29 2022 11:13 PM
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.
Aug 27 2023 10:45 PM
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