Calculate how many Gigabytes you need to extend your disk with, to gain a certain percentage free disk space, with this PowerShell script!

This evening i was asked if i did remember how to do a percentage calculation, in order to tell by how many gigabyte a disk needed to be extended to gain 20% free disk space.
The result was this PowerShell script, that i am sharing with you!



To use this script you need to load the function, and then run it with three parameters like this
Get-DiskExtentionInfo -CurrSpaceTotal 2000 -CurrSpaceFree 100 -TargetFreePerc 0.2

This will return as a object, you can either add it to a variable like this
$DiskInfo = Get-DiskExtentionInfo -CurrSpaceTotal 2000 -CurrSpaceFree 100 -TargetFreePerc 0.2

Or you can access the info directly like this
(Get-DiskExtentionInfo -CurrSpaceTotal 2000 -CurrSpaceFree 100 -TargetFreePerc 0.2).ExtendWith

Note: -TargetFreePrec  has to be like 0.2 for 20%, 0.5 for 50% and so on.

The Script: Get-DiskExtentionInfo

This script does nothing but calculating. But as always, only run scripts from the internet, at your own risk!


Example usage

Get-DiskExtentionInfo -CurrSpaceTotal 2000 -CurrSpaceFree 100 -TargetFreePerc 0.2

Will return the following information