Mon. Jan 3rd, 2022
Function Get-AllFileSizeFromFolder($web, $ctx, [String]$RelativeUrl, [Microsoft.SharePoint.Client.Folder]$Folder)
{
    $RelativeUrl = $RelativeUrl + "/" + $Folder.Name
    #Get All Files of the Folder
    $Ctx =  $Folder.Context
    $Ctx.load($Folder.files)
    $Ctx.ExecuteQuery()

    #Get all files in Folder
    #write-host $Folder.Name
    ForEach ($File in $Folder.files)
    {
        Get-AllFileSizeFromRoot -web $web -ctx $ctx -list $List -RelativeUrl $RelativeUrl -file $File
    }
             
    #Recursively Call the function to get files of all folders
    $Ctx.load($Folder.Folders)
    $Ctx.ExecuteQuery()
 
    #Exclude "Forms" system folder and iterate through each folder
    ForEach($SubFolder in $Folder.Folders | Where {$_.Name -ne "Forms"})
    {
        Get-AllFileSizeFromFolder -web $web -ctx $ctx -RelativeUrl $RelativeUrl -Folder $SubFolder
        $Global:FolderCounter++
    }
}

This website uses cookies. By continuing to use this site, you accept our use of cookies.