Today I was asked a fairly simple question by the client i.e. "Can you get me the list of large files in the SharePoint web application?" Why do you want that information and what's the use of it, right? Well… I walked into one of those SharePoint environments where the best practices were not followed and the Maximum Upload Size was set to 2GB. I recommended changing the maximum file upload size back to 50MB (default). Then client asked me to find out the files/documents which are larger than 50MB so that they can identify the large files and delete them from SP to improve the performance of SharePoint server or to resolve some bottlenecks.

In SharePoint 2010 the default Maximum Upload Size is 50MB. You can find the default value by navigating to Central Administration > Manage Web Applications > Select desired web application > General Settings as shown below.

Microsoft has set the hard limit on Maximum Upload Size and you can't change the value beyond 2GB. If you try to push the limit beyond 2GB, you'll get nice little error i.e. "The value for maximum upload size is invalid or out of range. The maximum value is 2047 MB".

Increasing the maximum upload size to 100MB shouldn't be that much of a stretch for your SharePoint environment, but be aware of the fact that it's going to push the upload size for the entire web application. If you want to be the BAD BOY who wants to go against the best practices, you can go ahead and change the value beyond 100MB, but it will affect the performance of your SharePoint server/other SharePoint applications when handling large files!

Bottom line is try NOT to go crazy with the default SharePoint values, there is a reason for every default value that is set by Microsoft. After all they are the ones who designed the app:)

Enough talking! Time for some coding! In this blog post I will develop a PowerShell script to enumerate all the site collections, sites, sub sites and document libraries in a given SharePoint web application to find the list of files which are larger than 50 MB.

The following PowerShell script would give you the list of files which are larger than 50MB in a SP web application. Just change the $filesize parameter based on your requirement and you should be good to go!!

I hope you've enjoyed the blog! Don't hesitate to contact me if you've any questions.

cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
Start-SPAssignment -Global
#Change the site url below
$Site = Get-SPSite http://sp2010.captech.net/
$spWeb = $Site.WebApplication
#Enter the target file size in MB
$fileSize = 50
[string]$fileUrl
Write-Host "------Checking the SP web app for large files------"
# Enumerate though all site collections, sites, sub sites and document libraries in a SP web app
if($spWeb -ne $null)
{
foreach ($siteColl in $spWeb.Sites)
{
foreach($subWeb in $siteColl.AllWebs)
{
foreach($List in $subWeb.Lists)
{
if($List.BaseType -eq "DocumentLibrary")
{
$ItemsColl = $List.Items
foreach ($item in $ItemsColl)
{
$itemSize = (($item.File.Length)/1024)/1024
if($itemSize -Ge $fileSize)
{
$itemUrl = $item.Web.Url + "/" + $item.Url;
Write-Host $itemUrl ", File size:: " $('{0:N2}' -f $itemSize) MB -ForegroundColor Green
}
}
}
}
}
}
}
Write-Host "---------DONE---------"
Stop-SPAssignment -Global