Forum Discussion

Abdullah_Shurjeel's avatar
Abdullah_Shurjeel
Copper Contributor
Dec 03, 2020
Solved

Powershell - Retrieve folder size for each folders in the output (Length Property).

My requirement is to retrieve all files from a directory when provided as an input to a certain folder level with the following properties: Name, FullName, Length, LastWriteTime.   Current code:  ...
  • ChrisBradshaw's avatar
    ChrisBradshaw
    Dec 17, 2020

    Abdullah_Shurjeel It looks like Measure-Object Windows PowerShell is behaving slightly differently to PSCore. I've changed the $Length= .... line to the following which appears to be working as expected.

    $Length= (Get-ChildItem $FileOrFolder.FullName -Recurse | Where-Object {$_.Attributes -notcontains "Directory"} | Measure-Object -Sum -Property Length).Sum

     

Resources