How to check size of a folder using powershell?

Copper Contributor

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?

2 Replies

@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

@powershellhdp 

 

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