Forum Discussion

powershellhdp's avatar
powershellhdp
Copper Contributor
Jun 05, 2022

How to check size of a folder using powershell?

Hi guys I am new in the world of powershell and trying to incorporate the job I do. How can I check size of a folder using powershell before copying it?

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    powershellhdp 

     

    Here's two simple examples:

     

    1. Get the size as a number (useful if the number's going to be used later on)

     

    (Get-ChildItem -Path "D:\Data\Temp\" -Recurse -Force | Measure-Object -Sum Length).Sum

     

     

    2. Get the size as a "nicely" formatted string (useless if you need a number later on):

     

    (Get-ChildItem -Path "D:\Data\Temp\" -Recurse -Force | Measure-Object -Sum Length).Sum.ToString("n0")

     

     

    Cheers,

    Lain

  • RiyazMSHelp's avatar
    RiyazMSHelp
    Copper Contributor

    powershellhdp 

     

    Get-ChildItem -Path C:\temp\ -Recurse | Measure-Object -Sum Length | Select-Object @{name='size(mb)';expression={$_.Sum/1mb}}

Resources