Last active
August 13, 2018 13:28
-
-
Save quonic/efadeebdf928e9ae97ad74404f522b8e to your computer and use it in GitHub Desktop.
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
| # Run this script to see connected hard disk status with nifty bar graph! | |
| $myDisk = Get-WmiObject -class win32_logicaldisk | |
| $myDisk | ForEach-Object { | |
| $free = ($_.freespace) | |
| $total = ($_.size) | |
| $used = $total - $free | |
| $perUsed = ($used / $total) * 100 | |
| $perFree = ($free / $total) * 100 | |
| $t = [math]::Round($total / 1gb) | |
| $f = [math]::Round($free / 1gb) | |
| $u = [math]::Round($used / 1gb) | |
| $pu = [math]::Round($perUsed) | |
| $pf = [math]::Round($perFree) | |
| Write-Host "Volume: "$_.VolumeName | |
| Write-Host "DeviceID: "$_.DeviceID | |
| Write-Host "Total: $t/Gb" | |
| Write-Host "Used: $u/Gb" | |
| Write-Host "Free: $f/Gb" | |
| Write-Host "% used: $pu%" | |
| Write-Host "% free: $pf%" | |
| # Create bar graph | |
| function drawBar { | |
| # Max width of bar | |
| $Width = 30 | |
| Write-Host '[' -NoNewline | |
| # Loop that animates the bar also scales the percentage so bar does not take up too much space | |
| (1..$($pu / 100 * $Width)) | ForEach-Object { | |
| # Tracks how many ticks to draw | |
| $tick++ | |
| Write-Host "$([char]0x25A0)" -NoNewline | |
| # Smaller number, faster animation | |
| Start-Sleep -Milliseconds 5 | |
| } | |
| # Calculates how much free space at end of the graph | |
| # Loop draws empty space and end of graph | |
| (1..$($Width - $tick)) | ForEach-Object { | |
| Write-Host ' ' -NoNewline | |
| } | |
| Write-Host ']' | |
| # Makes space between reports | |
| Write-Host "`n" | |
| } | |
| #Calls bar graph function | |
| drawBar | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment