-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
We use the following instruction to calculate a folder size
gci c:\my_folder | measure Length -sum
However, if the folder is empty, this instruction returns an error. This happens in PowerShell 5 to PowerShell 7 (Win 10 to Windows Server 2016 to 2019). The error message is:
Measure-Object: Cannot process argument because the value of argument “Property” is not valid. Change the value of the “Property” argument and run the operation again.
Expected behavior
Returns 0. No error. Especially, no red error message on the screen.
Actual behavior
Big RED error message on the screen. Even though 0 is returned, but the error message is annoying.
Environment data
c:\my_folder is an empty folder
My opinion
Measure-Object’s behaviour is correct. So the culprit is the folder object returned by PowerShell. The size property of the folder object should be set to zero by default.
Of course, if other changes in PowerShell's internal working could lead to the disappearance of the error message, I'm happy with that too.