PowerShell script to list folders and sizes

Last week @beningus, also a Dutch PowerShell interested IT Pro, contacted me for some assistance troubleshooting a script.
The purpose of that script was to list the directories of, for example, the homedirs on a fileserver in order to find the “big spenders” among the users. For this, we’ve written the following function:

 

 

11 comments

  1. Antonio says:

    Does not work. Do I need to add extra code to make it work or this is supposed to be completed code? It generates the following error:

    Get-FolderLength : Cannot bind argument to parameter ‘Path’ because it is an empty string.
    At line:14 char:17
    + Get-FolderLength <<<< $args[0]
    + CategoryInfo : InvalidData: (:) [Get-FolderLength], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Get-FolderLength

  2. Jeff Wouters says:

    Hi Antonio.,
    Changed the code, now it works.
    Thanks for the feedback.
    Jeff.

  3. Boycie says:

    For me, this returns 0MB for all folders found, please help!

  4. Jeff Wouters says:

    Hi Boycie,
    I’ve just tested the script in a newly installed VM, works for me…
    The only situations I could think of where it would give 0MB for the directories is where they are empty, have less than 0,005 MB of data in them or when there is not access to the date in the directories.
    Could you test and/or confirm this?
    Jeff.

  5. Ajit says:

    Jeff ,

    love your script thanks for the help

  6. Hein Traag says:

    Hello Jeff. Can this script be modified to search for certain extensions on a fileshare and then report them by mail to the sysadmin?

  7. Jeff Wouters says:

    Hi Hein,
    That wouldn’t be a modification but an entire new script 😉
    Jeff.

  8. Philip says:

    Hi Jeff

    This works great! But I’m stuck with 1 folder which does not return a size at all.
    If I do $objFSO.GetFolder($Folder.Fullname).Size it is empty … not even 0MB

  9. Philip says:

    Maybe I forgot to mention ….
    – There’s plenty of data in this folder
    – I’ve got full access to the whole folder hierarchy

  10. Jeff Wouters says:

    Hi Philip,
    If it works for all other folders, but not for just one then I would recommend a game of ‘look for the difference’.
    Think about folder attributes and such.
    If you find a difference (there has to be one), let me know and I can investigate / solve.
    Jeff.

  11. chewbie says:

    perhaps you can run it step-by step via Powershell ISE

Leave a Reply

Your email address will not be published. Required fields are marked *