folder size in bytes

I have the following to get the folder size in bytes, but when I run the script it says

ELAND 143520842837 bytes

But, when I go to the actual folder, and go to properties, it says the size is 143550466575 bytes. Why are they different? Which one is more accurate?

https://www.gngrninja.com/script-ninja/2016/5/24/powershell-calculating-folder-sizes

$DCS_location = '\\172.16.100.100\JetStor\DCS'
#$folders = Get-ChildItem -Path $DCS_location | Where-Object {$_.Extension -eq ""}
$folders = Get-ChildItem -Path $DCS_location | Where-Object {$_.name -eq "ELAND"}

foreach ($f in $folders) {

$folder_full_name = Get-ChildItem $f.FullName -recurse
$folder_size = ($folder_full_name | Measure-Object -property length -sum).Sum

Write-Host $f.Name $folder_size "bytes"

}

Is is a static file? A log file that is being written to? Regardless of the difference between the file system, does it need to accurate down to the byte?

PS C:\Users\Rob> 143520842837 / 1gb
133.664200861938

PS C:\Users\Rob> 143550466575 / 1gb
133.691790117882

PS C:\Users\Rob> [int](143520842837 / 1gb)
134

PS C:\Users\Rob> [int](143550466575 / 1gb)
134

Most likely it is the difference between size of bytes which is what you get in Length but then there is the “Size on Disk” which is the sum of the block size like 2 files that total 2.8K in 2 files but on disk it is 8K because the drive was formatted in 4K blocks.

It works for me. Length agrees with Size:, but not “Size on disk:”. I had to do “get-childitem -force” to get any hidden files. System files don’t seem to give it any trouble.

# find hidden files
ls -r -force | where mode -match h

but the delta here is very small, it wont be because of 4k formating. I think its because hidden files.

@Tony , can you give -force for Get-childItem and measure the sum, it treats hidden files as well.

I’m trying with the -Force now. I didn’t think about it.

Thank you, after adding

-Force

, it’s matching with the folder properties.