Get the size of files in a folder structure recursively


To get the size of specific files in a folder structure, for example log files, use the measure-object command, based on a selection you make.

First set the servers you want to check

Next, set the location on those servers

Next, get the files, in this case older then 15 days, and only the logfiles. The recurse option lets you find files in the entire folder structure.

Next, measure the result by adding the measure-command commandlet.

The output can be something like this:

If you want, you can do several thing with the output, like deleting old logfiles. The complete code for this would be:


Leave a Reply

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