I am new to the forum but not new to powershell. I see so many admins try and ‘out-think’ what powershell needs to do. What Bruce Payette envisioned when he led the team at MS and developed PS, he envisioned a modular, expandable scripting environment.
When getting info about folder sizes, one does not need 36 lines of code. This is a one-liner. The only trick is understanding the extensibility of powershell. All you have to do is go to the powershell gallery and install PSScripttools by Jeff Hicks. Simple. You then will have an easy way to make this a one-liner.
Here is an example of how easy getting folder size info is. Run the following on your my documents folder AFTER installing PSScriptTools by Jeff Hicks:
get-childitem . -Directory | Get-FolderSizeInfo | ft -View mb
PowerShell is supposed to make our lives easier- not a throwback to complex VB scripting…