Folder Size different results

This topic contains 3 replies, has 2 voices, and was last updated by  Max Kozlov 3 weeks, 6 days ago.

  • Author
    Posts
  • #80539

    Vinod Kumar
    Participant

    Trying to find the size of the folder under root of C:\ by excluding some folders. But when i run it gives me different size against by doing file explorer. For example under my test folder i can see there is 75 GB using explorer but the PS script tells me 305 GB. The code i used is

    $excludes = @("Program Files","Windows","Program Files (x86)","$Recycle.Bin","Intel","MININT","MSOCache","System Volume Information","temp","pagefile.sys")
    $startFolder = "C:\"
    $colItems = Get-ChildItem $startFolder -Force  -erroraction SilentlyContinue | Where {($_.PSIsContainer) -and ($excludes -notcontains $_.Name)} | Sort-Object
    $b=0 
    foreach ($i in $colItems)
    {
        $subFolderItems = Get-ChildItem $i.FullName -recurse -force -erroraction SilentlyContinue| Where-Object {$_.PSIsContainer -eq $false}  | Measure-Object -property Length -sum | Select-Object Sum
     
        $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1GB) + " GB"
        $i    
    }
    
    

    Any help is much appreciated

  • #80551

    Max Kozlov
    Participant

    there is a bunch of symlinks in C:\Users\Username ...

    • #80554

      Vinod Kumar
      Participant

      So use like this – $_.Attributes -notmatch 'ReparsePoint' ?

      Also why there is huge difference against 75 GB vs 330 GB under C:\test folder ? Very confusing

  • #80572

    Max Kozlov
    Participant

    yes, you need to exclude reparsepoints.

    1.
    I don't know what in your test folder but at least you output order confusing a bit 🙂
    I prefer to see item and it's parameters but not parameters and item

    2. I suppose that you measure folder size without UAC and compare it with Powershell:Administtrator measurements
    because PS have full access it measure all files but explorer just skip unaccessible

    for example under powershell without uac

    C:\ProgramData -- count: 48393, 6,83 GB
    d--h--       26.09.2017      9:30                ProgramData
    

    with uac (administrator)

    C:\ProgramData -- count: 48859, 9,15 GB
    d--h--       26.09.2017      9:30                ProgramData
    

    and explorer shows 48393, 6,83 GB

    the difference in C:\ProgramData\Microsoft\Search\Data

    btw, you can explore the differences youself 😉

You must be logged in to reply to this topic.