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