Folder Size different results

Welcome Forums General PowerShell Q&A Folder Size different results

This topic contains 3 replies, has 2 voices, and was last updated by

1 year, 5 months ago.

  • Author
  • #80539

    Points: 12
    Rank: Member

    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
    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"

    Any help is much appreciated

  • #80551

    Points: 0
    Rank: Member

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

    • #80554

      Points: 12
      Rank: Member

      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

    Points: 0
    Rank: Member

    yes, you need to exclude reparsepoints.

    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 😉

The topic ‘Folder Size different results’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort