Disk Space Usage Trend Analysis – Part 2


Following from Part 1 in this series, this section focuses on using the previously collected disk usage data and applies a ‘line of best fit’ linear trend-line (which will give us it’s “average” growth in GB/day).

There is a decent amount of maths going on here, to manually determine a linear trend in the format of y = mx + c. You don’t really need to understand how it works, but I’ll leave a link at the bottom for anyone interested in pursuing the methods to this madness.

To use the script below, you just need to ensure the $disklogdirectory is pointing to the same folder that you previously saved the disk usage logs to (c:\scripts\disklog from Part 1).

By default, this script looks at the last 30 days worth of data to determine the disk usage trend.  This is set by the $cutoffdate variable – and you can easily change the -30 to a larger negative number if you want to look for more long-term trends.

Also note, that there is a place-holder towards the very bottom of the script for the graph generation.  This is where the script from Part 3 will be inserted; though you can use just the Part 1 and Part 2 scripts without implementing the scripts from the next part.



When you run the above, you should see results similar what’s below. A message indicating which server is being processed, followed by the details of each disk (drive letter, slope, and C value).

The slope in this case is actually the average change per day (in GB).  So in this example, the D: drive on SQL01 is growing by an average of .31 GB per day – or around 9.4GB every month.


The C value is used in Part 3 when we plot the values and trend-line in a graph.

If you were just using Part 1 and Part 2 of this series, you could easily wrap the output above inside an If statement to only show you the disks where growth rate was greater than a certain value.




2 Comments Disk Space Usage Trend Analysis – Part 2

  1. Marc

    Hi Kamal,
    Great script, many thnx for that!

    I only get a failure in the part 2 script.

    Attempted to divide by zero.
    At D:\scripts\DPP\WFF\StorageTrendAnalyzing\StorageTrendAnalyzing_2.ps1:86 char:13
    + $slope = ($nsumxy – $sumxy) / ($nsumsquaredx – $sumxsquared);
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException

    I only lowerd the $cutoffDate to -6 days, further everything is the same as youre script. The txt file of the server collected more then 6 day’s of data.

    Can you please help me. I realy would like to use this script for analyzing.


  2. Kamal

    Hi Marc,

    hard to say without seeing your files with the hard disk usage data.
    All of the variables are initialized to zero – so, if you get a “divide by zero” it means the variables are still the default values.

    So, without seeing your exact setup, it might be that your data files are not in the correct directory ($filename variable) – OR – your data files don’t contain enough data for you $cutoffdays selected – OR – your date format settings are not consistent and it’s comparing DD/MM to MM/DD format (or vice-versa).


Leave a Reply

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