Find All Large Files and Generate Report in SharePoint using PowerShell
Requirement: Find large files in SharePoint.
SharePoint is not the replacement for network file shares when it comes to large files, archival. Detailed article here: SharePoint vs Network File Share – Which is best?. But who cares? End-Users started uploading large files which made us add few more disks to SQL Server. As part of the governance plan, defined a rule not to upload files larger than 50 MB.
Again, who cares? But SharePoint Administration team. Alright, decided to audit the Site collections for large files in a scheduled interval, once in a Month. Generate a report which gives insights on Large files uploaded to the site collections for the entire web application, and the script goes here:
How to Find Large Files in SharePoint Site Collection using PowerShell?
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function Get-LargeDocuments([string] $SiteCollURL)
{
Get-SPSite $SiteCollURL | Get-SPWeb -Limit All | ForEach-Object {
#Iterate through each document library
Foreach ($SPList in $_.Lists)
{
#Get Document Libraries
If($SPList.BaseType -eq "DocumentLibrary")
{
foreach ($item in $SPList.Items)
{
$Data = @{
"Web" = $_.Url
"list" = $SPList.Title
"Item URL" = $item.Url
"Item Name" = $item.Name
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"Size (MB)" = $item.File.Length/1MB
}
# add files larger than 50 MB to the Output
if($item.File.Length -gt 50MB)
{
Write-Host($_.Url +"/"+ $Item.Url)
New-Object PSObject -Property $data
}
}
}
}
}
}
#call the function
Get-LargeDocuments "https://intranet.crescent.com/sites/sales" | Export-Csv -NoTypeInformation -Path "C:\Temp\LargeDocuments.csv"
SharePoint PowerShell to Find Large Files in a web application:
Let’s find large files SharePoint web application with PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function Get-LargeDocuments([string] $WebAppURL)
{
$WebApp=Get-SPWebApplication $WebAppURL
foreach ($SPSite in $WebApp.Sites)
{
foreach ($SPWeb in $SPSite.AllWebs)
{
foreach ($SPList in $SPWeb.Lists)
{
# Get Document Libraries
if ($SPList.BaseType -eq "DocumentLibrary")
{
foreach ($item in $SPList.Items)
{
$data = @{
"Site" = $SPSite.Url
"Web" = $SPWeb.Url
"list" = $SPList.Title
"Item URL" = $item.Url
"Item Name" = $item.Name
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"Size (KB)" = $item.File.Length/1KB
"Size (MB)" = $item.File.Length/1MB
}
# add files larger than 50 MB to the Output
if($item.File.Length -gt 50MB)
{
Write-Host($SPSite.Url +"/"+ $item.Url)
New-Object PSObject -Property $data
}
}
}
$SPWeb.Dispose();
}
$SPSite.Dispose()
}
}
}
#call the function
Get-LargeDocuments "https://sharepoint.crescent.com" | Export-Csv -NoTypeInformation -Path "C:\LargeDocuments.csv"
and the output report:
There is a page that shows the largest files in a site collection and allows you to delete version history. I had it my bookmarks but accidentally deleted it and now can’t find it again 🙁 If anyone can post it it would be very useful.
Hi Sir,
Is there any script that can give site collection’s Large Files and Generate Report. I am looking for Site collection specific script.Thanks in advance.
Sure! post updated with the script to get large files on site collection level.
Do you have similar for SharePoint Online
Here you go: Find Large Lists in SharePoint Online using PowerShell
How can this script be changed to list all files modified older than a certain date instead of files larger than 50mb?
Sure! Here is the PowerShell script to help you:
Find All Documents Created or Modified by a Particular User in Specific Date Time
This works like a charm. Thanks you
Will this script work in SharePoint 2003 systems?