none
[URGENT] Report of document library files RRS feed

  • Question

  • I would like to generate a detailed summary of document library files that have been added/modified/deleted respective site level and then trigger in single email alert to group of users every week of those list of sites with above details(added/modified/deleted files). please let me know if we shall use some reporting tools /coding for achieving the same.

    Blitz



    • Edited by sree_23 Thursday, July 11, 2019 11:02 AM
    Thursday, July 11, 2019 10:25 AM

Answers

  • Hi Sree,

    You could refer Sharath's PowerShell script, it will get the Document Library file item details and export to a CSV file, then you could send email with this generated CSV file to target users.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Friday, July 12, 2019 10:36 AM
    Friday, July 12, 2019 6:27 AM
  • Hi Sree,

    This PowerShell script generates detailed report on the given SharePoint library's inventory in addition with its storage data. The output report contains:
    File Name, File Size(KB), Versions Size(KB), Total File Size(KB), Created on, Last Modified, Created by, Parent Folder, URL

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    
    # Function to retrieve detailed Library storage Report
    Function GetLibraryStorageRpt($Folder)
    {
        #Array to hold Storage data for all files
        $StorageDataCollection = @()
        
        $FileSize = 0
        $TotalFileSize = 0
        foreach ($File in $Folder.Files)
        {
            #Get File Size
            $FileSize = $File.TotalLength
            
            $VersionSize = 0
            #Get the Versions Size
            foreach ($FileVersion in $File.Versions)
            {
                $VersionSize +=$FileVersion.Size
            }
            $TotalFileSize = $FileSize + $VersionSize
      
            $StorageDataResult = New-Object PSObject
     
            $StorageDataResult | Add-Member -type NoteProperty -name "File Name" -value $File.Name
            $StorageDataResult | Add-Member -type NoteProperty -name "File Size(KB)" -value $($FileSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Versions Size(KB)" -value $($VersionSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Total File Size(KB)" -value $($TotalFileSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Created on" -value $File.TimeCreated 
            $StorageDataResult | Add-Member -type NoteProperty -name "Last Modified" -value $File.TimeLastModified 
            $StorageDataResult | Add-Member -type NoteProperty -name "Created by" -value $File.Author.Name        
            $StorageDataResult | Add-Member -type NoteProperty -name "Parent Folder" -value $File.ParentFolder.URL
            $StorageDataResult | Add-Member -type NoteProperty -name "URL" -value $File.URL
    
            $StorageDataCollection += $StorageDataResult
            #Write-Host "Processing File:"$File.Name
        } 
            #Get Files in Sub Folders
            foreach ($SubFolder in $Folder.SubFolders)
            {   
             if($SubFolder.Name -ne "Forms") #Leave "Forms" Folder which has List default Aspx Pages.
                 {
                    GetLibraryStorageRpt($SubFolder)          
                 }
            }   
        return $StorageDataCollection
    }
    
    #Input Variables 
    $WebURL = "http://sharepoint.crescent.com/sites/operations" 
    $ListName ="Documents"
    
    #Get the List
    $List = Get-SPWeb $WebURL | Select -ExpandProperty "Lists" | Where-Object{$_.Title -eq $ListName}
    
    #Call the function to get data 
    $StorageDetails = GetLibraryStorageRpt($List.RootFolder)
    
    write-host "Total Number of Files:" $List.ItemCount 
    write-host "Library Created by:" $List.Author
    
    #Calculate the Total Size
    $TotalSize = ($StorageDetails | Measure-Object 'Total File Size(KB)' -Sum | Select -expand Sum)  
    Write-host "Library Size in MB: "([Math]::Round( ($TotalSize/1024),2))
    
    #Export the data to CSV File
    $StorageDetails | sort-object "Total File Size" -descending | Export-csv "$($ListName)_LibraryStroageRpt.csv" -notypeinformation
    Write-Host "Storage Report has been Generated!"

    place this script in a task scheduler and make it run for every week to get the reports and also you could assign email in the powershell to get the reports all the users mentioned over there, below article will help you how to send an email from powershell.

    http://www.sharepointdiary.com/2016/11/sharepoint-online-powershell-to-send-email.html

    Thanks & Regards,


    sharath aluri

    Thursday, July 11, 2019 9:00 PM

All replies

  • Hi Sree,

    This PowerShell script generates detailed report on the given SharePoint library's inventory in addition with its storage data. The output report contains:
    File Name, File Size(KB), Versions Size(KB), Total File Size(KB), Created on, Last Modified, Created by, Parent Folder, URL

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    
    # Function to retrieve detailed Library storage Report
    Function GetLibraryStorageRpt($Folder)
    {
        #Array to hold Storage data for all files
        $StorageDataCollection = @()
        
        $FileSize = 0
        $TotalFileSize = 0
        foreach ($File in $Folder.Files)
        {
            #Get File Size
            $FileSize = $File.TotalLength
            
            $VersionSize = 0
            #Get the Versions Size
            foreach ($FileVersion in $File.Versions)
            {
                $VersionSize +=$FileVersion.Size
            }
            $TotalFileSize = $FileSize + $VersionSize
      
            $StorageDataResult = New-Object PSObject
     
            $StorageDataResult | Add-Member -type NoteProperty -name "File Name" -value $File.Name
            $StorageDataResult | Add-Member -type NoteProperty -name "File Size(KB)" -value $($FileSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Versions Size(KB)" -value $($VersionSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Total File Size(KB)" -value $($TotalFileSize/1KB)
            $StorageDataResult | Add-Member -type NoteProperty -name "Created on" -value $File.TimeCreated 
            $StorageDataResult | Add-Member -type NoteProperty -name "Last Modified" -value $File.TimeLastModified 
            $StorageDataResult | Add-Member -type NoteProperty -name "Created by" -value $File.Author.Name        
            $StorageDataResult | Add-Member -type NoteProperty -name "Parent Folder" -value $File.ParentFolder.URL
            $StorageDataResult | Add-Member -type NoteProperty -name "URL" -value $File.URL
    
            $StorageDataCollection += $StorageDataResult
            #Write-Host "Processing File:"$File.Name
        } 
            #Get Files in Sub Folders
            foreach ($SubFolder in $Folder.SubFolders)
            {   
             if($SubFolder.Name -ne "Forms") #Leave "Forms" Folder which has List default Aspx Pages.
                 {
                    GetLibraryStorageRpt($SubFolder)          
                 }
            }   
        return $StorageDataCollection
    }
    
    #Input Variables 
    $WebURL = "http://sharepoint.crescent.com/sites/operations" 
    $ListName ="Documents"
    
    #Get the List
    $List = Get-SPWeb $WebURL | Select -ExpandProperty "Lists" | Where-Object{$_.Title -eq $ListName}
    
    #Call the function to get data 
    $StorageDetails = GetLibraryStorageRpt($List.RootFolder)
    
    write-host "Total Number of Files:" $List.ItemCount 
    write-host "Library Created by:" $List.Author
    
    #Calculate the Total Size
    $TotalSize = ($StorageDetails | Measure-Object 'Total File Size(KB)' -Sum | Select -expand Sum)  
    Write-host "Library Size in MB: "([Math]::Round( ($TotalSize/1024),2))
    
    #Export the data to CSV File
    $StorageDetails | sort-object "Total File Size" -descending | Export-csv "$($ListName)_LibraryStroageRpt.csv" -notypeinformation
    Write-Host "Storage Report has been Generated!"

    place this script in a task scheduler and make it run for every week to get the reports and also you could assign email in the powershell to get the reports all the users mentioned over there, below article will help you how to send an email from powershell.

    http://www.sharepointdiary.com/2016/11/sharepoint-online-powershell-to-send-email.html

    Thanks & Regards,


    sharath aluri

    Thursday, July 11, 2019 9:00 PM
  • Hi Sree,

    You could refer Sharath's PowerShell script, it will get the Document Library file item details and export to a CSV file, then you could send email with this generated CSV file to target users.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Friday, July 12, 2019 10:36 AM
    Friday, July 12, 2019 6:27 AM