kwizcom banner advertisement

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 to add few more disks at SQL Server. As part of governance plan, defined a rule to 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 the 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:
Lets 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
Find All Large Files and Generate Report in SharePoint using PowerShell Find All Large Files and Generate Report in SharePoint using PowerShell Reviewed by Salaudeen Rajack on September 02, 2012 Rating: 5

9 comments:

  1. Will this script work in SharePoint 2003 systems?

    ReplyDelete
  2. This works like a charm. Thanks you

    ReplyDelete
  3. How can this script be changed to list all files modified older than a certain date instead of files larger than 50mb?

    ReplyDelete
  4. Do you have similar for SharePoint Online

    ReplyDelete
  5. 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.

    ReplyDelete
    Replies
    1. Sure! post updated with the script to get large files on site collection level.

      Delete
  6. 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.

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.