Skip to content

Instantly share code, notes, and snippets.

@Fabaderheld
Last active July 6, 2024 16:51
Show Gist options
  • Save Fabaderheld/e8c0d3144a4b057df1f62b43b4a658ba to your computer and use it in GitHub Desktop.
Save Fabaderheld/e8c0d3144a4b057df1f62b43b4a658ba to your computer and use it in GitHub Desktop.
Convert DF in powershell

df -h > df_output.txt

Read the contents of the df_output.txt file

$dfOutput = Get-Content -Path df_output.txt

Parse the output

$parsedOutput = $dfOutput | ForEach-Object { if ($_ -match '^\s*Filesystem\s+Size\s+Used\s+Avail\s+Use%\s+Mounted on') { return # Skip the header line } $parts = -split $_ [PSCustomObject]@{ Filesystem = $parts[0] Size = $parts[1] Used = $parts[2] Avail = $parts[3] UsePercent = $parts[4] MountedOn = $parts[5] } }

Display the parsed output

$parsedOutput | Format-Table -AutoSize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment