title: Display directory structure with size in Powershell
body: <p>Trying to have "dir" command that displays size of the sub folders and files.
  After googling "powershell directory size", I found thew two useful links</p>
  
  <ol>
  <li>Determining the Size of a Folder  <a href="http://technet.microsoft.com/en-us/library/ff730945.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/library/ff730945.aspx</a> </li>
  <li>PowerShell Script to Get a Directory Total Size <a href="https://stackoverflow.com/questions/809014/powershell-script-to-get-a-directory-total-size">PowerShell Script to Get a Directory Total Size</a></li>
  </ol>
  
  <p>These soultions are great, but I am looking for something resembles "dir" output, handy and simple and that I can use anywhere in the folder structure.</p>
  
  <p>So, I ended up doing this, Any suggestions to make it simple, elegant, efficient.</p>
  
  <pre><code>Get-ChildItem | 
  Format-Table  -AutoSize Mode, LastWriteTime, Name,
       @{ Label="Length"; alignment="Left";
         Expression={ 
                      if($_.PSIsContainer -eq $True) 
                          {(New-Object -com  Scripting.FileSystemObject).GetFolder( $_.FullName).Size}  
                      else 
                          {$_.Length} 
                    }
       };  
  </code></pre>
  
  <p>Thank you.</p>