Get Large File Details From SharePoint Site

Introduction

 
Sometimes there is a requirement to get all the file details that are above a certain size.  To do so manuallly is a tedious task, so I am writing this script to export the file details which is greater than 50mb
 
Download and Install the pnp modules,
 
for SPOnline- https://github.com/pnp/PnP-PowerShell/releases/download/3.20.2004.0/SharePointPnPPowerShellOnline.msi
for sp2019- https://github.com/pnp/PnP-PowerShell/releases/download/3.20.2004.0/SharePointPnPPowerShell2019.msi
for sp2016-https://github.com/pnp/PnP-PowerShell/releases/download/3.20.2004.0/SharePointPnPPowerShell2016.msi
for sp2013-https://github.com/pnp/PnP-PowerShell/releases/download/3.20.2004.0/SharePointPnPPowerShell2013.msi
 
Open Powershell online management shell or Windows powershell and run the following script (save files as .ps1 format).
  1. $SiteURL = "site url"  
  2. $CSVPath = "D:\BigFiles.csv"  
  3. Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
  4. $FileDetails = @()  
  5. $DocumentLib = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}  
  6. ForEach ($List in $DocumentLib)  
  7. {  
  8.     Write-host "Processing Library:"$List.Title -f Green  
  9.     $Files = Get-PnPListItem -List $List -PageSize 500 | Where {($_.FieldValues.FileLeafRef -like "*.*") -and ($_.FieldValues.SMTotalFileStreamSize/1MB -gt 50)}  
  10.     ForEach ($File in $Files)  
  11.     {  
  12.         $FileDetails += [PSCustomObject][ordered]@{  
  13.             Library         = $List.Title  
  14.             FileName        = $File.FieldValues.FileLeafRef  
  15.             URL              = $File.FieldValues.FileRef  
  16.             Size            = [math]::Round(($File.FieldValues.SMTotalFileStreamSize/1MB),2)  
  17.         }  
  18.     }  
  19. }  
  20. $FileDetails | Sort-object Size -Descending  
  21. $FileDetails | Export-Csv -Path $CSVPath -NoTypeInformation  
That's it. After successful execution, the CSV file will be downloaded in its relevant path. I hope this helps someone. Happy coding! :)