Total Size of Preservation Hold Libraries

%3CLINGO-SUB%20id%3D%22lingo-sub-2402051%22%20slang%3D%22en-US%22%3ETotal%20Size%20of%20Preservation%20Hold%20Libraries%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2402051%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20wondering%20if%20someone%20can%20help%20with%20a%20PowerShell%20script%20to%20retrieve%20the%20size%20of%20Preservation%20hold%20libraries%20in%20all%20the%20SharePoint%20Sites%20and%20OneDrive.%26nbsp%3B%20I%20need%20to%20calculate%20the%20total%20space%20being%20used%20by%20items%20in%20Preservation%20Hold%20Libraries%20in%20our%20tenant.%26nbsp%3B%20%26nbsp%3BThanks%20so%20much%20for%20the%20help%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2402051%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOneDrive%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2889589%22%20slang%3D%22en-US%22%3ERe%3A%20Total%20Size%20of%20Preservation%20Hold%20Libraries%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2889589%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F848695%22%20target%3D%22_blank%22%3E%40Amrah_Chughtai%3C%2FA%3E%26nbsp%3BThis%20may%20be%20a%20bit%20late%20but%20here's%20something%20I%20wrote%20that%20should%20point%20you%20in%20the%20correct%20direction.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20below%20PowerShell%20script%20requires%20modules%20for%20SharePoint%20Online%20Powershell%20and%20SharePoint%20PnP%20to%20be%20available%20on%20the%20machine.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKnown%20issues%3A%3C%2FP%3E%3CUL%3E%3CLI%3EThe%20script%20does%20not%20process%20sub-sites%2C%20this%20can%20probably%20be%20easily%20fixed.%3C%2FLI%3E%3CLI%3EThe%20%22Measure-PNPList%22%20cmdlet%20fails%20if%20the%20number%20of%20items%20in%20the%20preservation%20hold%20library%20exceeds%20the%20list%20view%20limit.%20The%20limit%20can%20be%20changed%20on%20the%20target%20sites%2C%20not%20sure%20if%20it%20can%20be%20done%20using%20PowerShell.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EHope%20this%20helps%20and%20perhaps%20someone%20else%20will%20improve%20and%20share%20a%20new%20version%20of%20the%20script%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24Out%20%3D%20%40()%0A%0A%24sites%20%3D%20Get-SPOSite%20-Limit%20ALL%0A%24Sites%20%3D%20%24Sites%20%7C%20Sort-Object%20StorageUsageCurrent%20-Descending%0A%0Aforeach%20(%24Site%20in%20%24Sites)%7B%0A%0AConnect-PnPOnline%20-Url%20%24site.Url%20-Interactive%0A%0A%24SiteSize%20%3D%20%24Site.StorageUsageCurrent%0A%24PHLib%20%3D%20Get-PnPList%20-Identity%20PreservationHoldLibrary%0A%0Aif(%24PHLib)%7B%0A%24PHSize%20%3D%20(%24PHLib%20%7C%20Measure-PnPList).TotalFileSize%0A%24PHSize%20%3D%20%24PHSize%20%2F%201024%20%2F%201024%0A%7D%0Aelse%20%7Bcontinue%7D%0A%0Aif(!%24PHSize)%7Bcontinue%7D%0A%0A%24item%20%3D%20New-Object%20PSObject%0A%24item%20%7C%20Add-Member%20-type%20NoteProperty%20-Name%20'Url'%20-Value%20%24site.Url%0A%24item%20%7C%20Add-Member%20-type%20NoteProperty%20-Name%20'SiteSizeMB'%20-Value%20%24SiteSize%0A%24item%20%7C%20Add-Member%20-type%20NoteProperty%20-Name%20'PreservationSizeMB'%20-Value%20(%5Bmath%5D%3A%3ARound(%24PHSize))%0A%24item%20%7C%20Add-Member%20-type%20NoteProperty%20-Name%20'PreservationPercentage'%20-Value%20(%5Bmath%5D%3A%3ARound(((%24PHSize%2F%24SiteSize)*100)))%0A%0A%24item%0A%0A%24out%20%2B%3D%24item%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Senior Member

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.

1 Reply

@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
}