Created
May 23, 2019 13:36
-
-
Save Slusho/a3c52ce5fc299aacb91b1d8e42209060 to your computer and use it in GitHub Desktop.
Reports logical disk status and graph of disk usage
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
# Run this script to see connected hard disk status with nifty bar graph! | |
Begin { | |
function Get-BarGraph($Percent){ | |
# Max width of graph | |
$Width = 20 | |
Write-Host '['-NoNewline | |
# Loop that animates the bar, also scales the percentage so bar does not take up too much space | |
While($tick++ -le $Percent/100*$Width-1){ | |
if ($tick -le $Width / 1.7) { | |
Write-Host "$([char]0x25A0)" -NoNewline -ForegroundColor Green | |
} | |
elseif ($tick -le $Width / 1.1) { | |
Write-Host "$([char]0x25A0)" -NoNewline -ForegroundColor Yellow | |
} | |
else { | |
Write-Host "$([char]0x25A0)" -NoNewline -ForegroundColor Red | |
} | |
# Smaller number, faster animation | |
Start-Sleep -Milliseconds 10 | |
} | |
# Calculates how much free space at end of the graph | |
$spaceLeft = ((1)*$Width) - $tick | |
# Loop draws empty space and end of graph | |
While($add++ -le $spaceLeft){ | |
Write-Host ' ' -NoNewline | |
} | |
Write-Host ']' | |
} | |
$GetDisk = read-host | |
$myDisk = Get-WmiObject -class win32_logicaldisk -ComputerName $GetDisk | |
} | |
Process { | |
$myDisk | ForEach-Object { | |
if ($_.Drivetype -eq 3) { | |
$TotalSpace = [Math]::Round($_.Size / 1gb) | |
$FreeSpace = [Math]::Round($_.Freespace / 1gb) | |
$UsedSpace = [Math]::Round(($_.Size - $_.FreeSpace) / 1gb) | |
$PercentUsed = [Math]::Round((($_.Size - $_.FreeSpace) / $_.Size) * 100) | |
$PercentFree = [Math]::Round(($_.FreeSpace / $_.Size) * 100) | |
$param = @{ | |
Volume = $_.VolumeName | |
DriveLetter = $_.DeviceID | |
TotalSpace = "$TotalSpace GB" | |
UsedSpace = "$UsedSpace GB" | |
FreeSpace = "$FreeSpace GB" | |
PercentUsed = "$PercentUsed %" | |
PercentFree = "$PercentFree %" | |
} | |
$Results = New-Object -TypeName PSObject -Property $param | |
$Results | ft | |
Get-BarGraph $Results.PercentUsed.Replace('%', '') | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment