Skip to content

Instantly share code, notes, and snippets.

@Timberfang
Last active December 11, 2022 19:47
Show Gist options
  • Save Timberfang/e27bf1318b82e1549edbc751ad70ccba to your computer and use it in GitHub Desktop.
Save Timberfang/e27bf1318b82e1549edbc751ad70ccba to your computer and use it in GitHub Desktop.
Get a percentage of how full your storage drives are.
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