Last active
July 11, 2025 16:39
-
-
Save przemoc/561535d1a82b9cb2ab5c19c921f0b199 to your computer and use it in GitHub Desktop.
Disk Free imitation in PowerShell
This file contains hidden or 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
## Profile location | |
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles | |
# CurrentUserCurrentHost profile always runs last: | |
# $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 | |
# It is the profile typically meant as your PowerShell profile. | |
## Disk Free imitation in PowerShell: | |
# df # all filesystems | |
# df C: # drive letters can be written with or without colon (:) | |
# df D,E # can be separated by using commas or | |
# df C D E # spaces, but never both | |
# df C:\Users # providing paths is also supported | |
# df . # including dot for current working directory | |
function df { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$false, Position=0, ValueFromRemainingArguments=$true)] | |
[string[]] $Name | |
) | |
if (-not $PSBoundParameters.ContainsKey('Name')) { | |
Get-Volume | |
} else { | |
$volumes = $Name | ForEach-Object { | |
if ($_ -match '^[A-Za-z]:?$') { | |
Get-Volume -DriveLetter $_.TrimEnd(':') | |
} else { | |
Get-Volume -FilePath (Resolve-Path $_) | |
} | |
} | |
$volumes | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment