I have a script, where it loops through the whole site collection and starts calculating the size of each list in the site, and calculates each document size (PDF or word document) to determine the total size for the files uploaded onto the site, as well as calculating image files (jpg, png..etc.), and at the end it prints the total size of each file type, and the totals size of the content as a whole.

$siteURL = "http://siteurl" 
$site = new-object Microsoft.SharePoint.SPSite($siteURL)
$fsSubCounter = 0
$fsCounter = 0
foreach ($web in $site.AllWebs)
    foreach ($list in $web.Lists)
        if($list.BaseType -eq "DocumentLibrary")   
            $listSize = 0
            $imageSizeCounter = 0
            $fileSizeCounter = 0
            foreach ($item in $list.Items)
                #check image
                if($item.File.Name -like "*.jpg" -or $item.File.Name -like "*.png" -or $item.File.Name -like "*.jpeg" -or $item.File.Name -like "*.gif" -or $item.File.Name -like "*.bmp")
                    $imageSizeCounter +=  ($item.file).length

                #check document
                if($item.File.Name -like "*.pdf" -or $item.File.Name -like "*.PDF" -or $item.File.Name -like "*.doc" -or $item.File.Name -like "*.docx" -or $item.File.Name -like "*.xls" -or $item.File.Name -like "*.xlsx" )
                    $fileSizeCounter +=  ($item.file).length

                #check list size
                $listSize += ($item.file).length
        "Site: "+$web.Title+", List Name: "+$list.Title+", Size: " +[Math]::Round(($listSize/1MB),2)+" MB"  
        $fsSubCounter = [Math]::Round(($fileSizeCounter/1GB),2)
        $fsCounter =  $fsCounter + $fsSubCounter

        $imgSubCounter= [Math]::Round(($imageSizeCounter/1GB),2)
        $imgcounter = $imgcounter + $imgSubCounter          

        $subcounter = [Math]::Round(($listSize/1GB),2)
        $counter=$counter+ $subcounter
Write-Host "Total File size: " $fsCounter "GB"
Write-Host "Images size" : $imgcounter "GB"
Write-Host "Total size: " $counter "GB"

the result after the script completes executing is as follows:

enter image description here

The total size of the lists shown above is exceeding the current storage used space value for the site colleciton:

enter image description here

So I'm wondering what could be wrong with the script? is the logic of the script wrong or is any piece of the sciprt misplaced?

Your help is appreciated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.