Sunday, September 2, 2012

Find All Large Files and Generate Report in SharePoint using PowerShell

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:

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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

4 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

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...