locked
Powershell FolderSize RRS feed

  • Question

  • 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
    Monday, September 25, 2017 2:52 PM

Answers

All replies

  • I would recommend reading the following: https://stackoverflow.com/questions/19553063/get-childitem-reports-different-value-to-explorer

    A few Googles should shed some light on how to correct the discrepancies

    Monday, September 25, 2017 3:04 PM
  • Thanks. But using the ReparsePoint did not get me the right number. Since my HDD is only 256 GB, but the test folder it showing as 330 GB. So am really confused now
    Monday, September 25, 2017 4:16 PM
  • Hi,

    I agree with I.T Delinquent,

    Based on my research, I'd like to explain that the files displayed by File Explorer might be different from the Get-ChildItem with the -Force parameters.

    In addition, you could have a try with the -Attributes parameters. For example: -Attributes H,!H would list all the hidden and not hidden files and folders, for your reference:
    Get-ChildItem -Path <String> -Recurse -Attributes H,!H

    For more information about Get-ChildItem and -Attributes parameters, please refer to the following article:
    Get-ChildItem
    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-5.1
    FileAttributes Enumeration
    https://msdn.microsoft.com/en-us/library/system.io.fileattributes(lightweight).aspx

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by I.T Delinquent Tuesday, September 26, 2017 11:28 AM
    • Marked as answer by vinod7 Thursday, October 5, 2017 12:11 AM
    Tuesday, September 26, 2017 5:01 AM
  • Hi,

    Just want to confirm the current situations.

    If you already tried them or the issue remains after trying them, please don’t hesitate to tell me. I will do more research and try my best to give you helpful suggestions.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 29, 2017 6:21 AM
  • Hi,

    I am checking how the issue is going, if you still have any questions, please feel free to contact us.

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.

    Appreciate for your feedback.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, October 4, 2017 7:47 AM
  • Thanks.
    Thursday, October 5, 2017 12:11 AM