Author Posts

September 25, 2017 at 2:51 pm

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

September 25, 2017 at 3:47 pm

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

September 25, 2017 at 3:49 pm

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

September 26, 2017 at 7:24 am

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 😉