0

How do I get all the files in my SharePoint 2013 server? It will list the document libraries but the .csv will have no information printed on it.

I am able to run this fine on SharePointOnline and it will print the information in the .csv file.

Thanks for any assistance!

#Config Variables
$SiteURL = "https://sharepoint.com/"
$CSVFilePath="C:\Users\user\Desktop\file.csv"

Import-Module SharePointPnPPowerShellOnline
Connect-PnpOnline -Url $SiteURL -Credential $cred

 
 
#Get all document libraries
$FileData = @()
$DocumentLibraries = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}
 
#Iterate through document libraries
ForEach ($List in $DocumentLibraries)
{
    Write-host "Processing Library:"$List.Title -f Yellow
     
    #Get All Files of the library with size > 100MB
    #$Files = Get-PnPListItem -List $List -PageSize 500 | Where {($_.FieldValues.FileLeafRef -like "*.*") -and ($_.FieldValues.SMTotalFileStreamSize/1MB -gt 100)}
    if($Files.BaseType -eq "DocumentLibrary")  
    {
        #Collect data from each files
        ForEach ($File in $Files)
        {
            $FileData += [PSCustomObject][ordered]@{
                Library         = $List.Title
                FileName        = $File.FieldValues.FileLeafRef
                URL              = $File.FieldValues.FileRef
                Size            = [math]::Round(($File.FieldValues.SMTotalFileStreamSize/1MB),2)
            }
        }
    }
}
#Export Files data to CSV File
$FileData | Sort-object Size -Descending
$FileData | Export-Csv -Path $CSVFilePath -NoTypeInformation


#Read more: https://www.sharepointdiary.com/2018/11/sharepoint-online-find-all-large-files-using-powershell.html#ixzz6Yy8ueFyy
1

In SharePoint 2013, not seeing property "SMTotalFileStreamSize", you may try File_x0020_Size instead

This worked for me (partial script)

#Get all document libraries
$FileData = @()
$DocumentLibraries = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}
 
#Iterate through document libraries
ForEach ($List in $DocumentLibraries)
{
    Write-host "Processing Library:"$List.Title -f Yellow
     
    #Get All Files of the library with size > 100MB
    $Files = Get-PnPListItem -List $List # -PageSize 500 | Where {($_.FieldValues.FileLeafRef -like "*.*") -and ($_.FieldValues.SMTotalFileStreamSize/1MB -gt 100)}

    #if($Files.BaseType -eq "DocumentLibrary")  
    #{
        #Collect data from each files
        ForEach ($File in $Files)
        {
            $FileData += [PSCustomObject][ordered]@{
                Library         = $List.Title
                FileName        = $File.FieldValues.FileLeafRef
                URL              = $File.FieldValues.FileRef
                Size            = $File.FieldValues.File_x0020_Size
            }
        }
    #}
}


#Export Files data to CSV File
$FileData | Sort-object Size -Descending
$FileData | Export-Csv -Path $CSVFilePath -NoTypeInformation

How property File_x0020_Size can be found:

enter image description here

3
  • I’ll give it a shot later this evening. Thanks. How about file names and url? It isn’t recognizing it either. – williswin Sep 25 '20 at 21:02
  • That was exactly what I needed, thank you! How did you determine the property was File_x0020_Size? Is there a way to seach through the filter? – williswin Sep 26 '20 at 3:19
  • 1
    Glad to know that it helped. I found the property from intellisense in PS ISE. After completing the "ForEach" loop, the variables of the last iteration are still alive, so you can check the values. Posted a screenshot on this.. – Matiur Rahman Sep 26 '20 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.