I’m trying to modify a script that check the size of folders in a particular path, but get an error message when it hits a folder of zero bytes. Is there a way to use a Try Catch to suppress the error message?
Code snippet
$size = (Get-ChildItem $_.FullName -Recurse |
WHERE {-not $_PSIsContainer} |
Measure-Object -Sum Length).Sum
Error Message
Measure-Object : The property "Length" cannot be found in the input for any objects.
At line:64 char:13
+ Measure-Object -Sum Length).Sum
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException
+ FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
Thanks
Tony