Forum Discussion
powershellhdp
Jun 05, 2022Copper Contributor
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?
- LainRobertsonSilver Contributor
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
- RiyazMSHelpCopper Contributor
Get-ChildItem -Path C:\temp\ -Recurse | Measure-Object -Sum Length | Select-Object @{name='size(mb)';expression={$_.Sum/1mb}}