Last active
December 11, 2022 19:47
-
-
Save Timberfang/e27bf1318b82e1549edbc751ad70ccba to your computer and use it in GitHub Desktop.
Get a percentage of how full your storage drives are.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-StrictMode -Version 3.0 | |
#Requires -Version 5.1 | |
# Get used space on a drive, then warn if storage usage exceeds 65%. | |
function Get-DriveInfo { | |
[CmdletBinding()] | |
param( | |
$InformationPreference= "Continue", | |
[int]$WarnPercent = '75' | |
) | |
Get-PSDrive -PSProvider FileSystem | ForEach-Object { | |
if (($_.Used / ($_.Free + $_.Used)).ToString("P") -ge $WarnPercent) { | |
[PSCustomObject]@{ | |
Name = $_.Name | |
"Used (GB)" = $_.Used | |
"Free (GB)" = $_.Free | |
"Total (GB)" = ($_.Used + $_.Free) | |
"Used (%)" = (($_.Used / ($_.Free + $_.Used)).ToString("P") + ' - Warning!') | |
Provider = $_.Provider | |
Root = $_.Root | |
} | |
} | |
else { | |
[PSCustomObject]@{ | |
Name = $_.Name | |
"Used (GB)" = $_.Used | |
"Free (GB)" = $_.Free | |
"Total (GB)" = ($_.Used + $_.Free) | |
"Used (%)" = ($_.Used / ($_.Free + $_.Used)).ToString("P") | |
Provider = $_.Provider | |
Root = $_.Root | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment