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 "http://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 "http://sharepoint.crescent.com" | Export-Csv -NoTypeInformation -Path "C:\LargeDocuments.csv"

and the output report:

how to find large files in sharepoint 2013 using powershell

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

9 thoughts on “Find All Large Files and Generate Report in SharePoint using PowerShell

Leave a Reply