Created
December 29, 2015 09:14
-
-
Save tobyqin/73f7ca223e5cf051bbba to your computer and use it in GitHub Desktop.
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
Function Get-DiskInfo | |
{ | |
Param( | |
$ComputerName = $env:COMPUTERNAME, | |
[Switch]$PassThru | |
) | |
Function Get-ColorSplat | |
{ | |
# Create color Splats | |
$C1 = @{ForegroundColor="Green";BackgroundColor="DarkGreen"} | |
$C2 = @{ForegroundColor="Yellow";BackgroundColor="DarkYellow"} | |
$C3 = @{ForegroundColor="White";BackgroundColor="DarkRed"} | |
$C4 = @{ForegroundColor="Blue";BackgroundColor="Gray"} | |
# Create color constants in the previous scope. | |
New-Variable -Name "Good" -Value $C1 -Scope 1 | |
New-Variable -Name "Problem" -Value $C2 -Scope 1 | |
New-Variable -Name "Bad" -Value $C3 -Scope 1 | |
New-Variable -Name "Header" -Value $C4 -Scope 1 | |
} # End: Get-ColorSplat | |
Function Write-ColorOutput | |
{ | |
Param($DiskInfo) | |
# Display the headers. | |
Write-host "DiskInfo | FreeSpaceGB | PercentFreeSpace" | |
# Display the data. | |
ForEach ($D in $DiskInfo) | |
{ | |
$DeviceID = $D.DeviceID.PadRight(6) | |
$FSGB = $D.FreeSpaceGB.ToString().PadRight(6).Remove(5) | |
$PFS = $D.PercentFS.ToString().PadRight(6).Remove(5) | |
If ($D.PercentFS -ge 80) | |
{ Write-Host "$($DeviceID) | $($FSGB) | $($PFS)" @Good } | |
ElseIf (($D.PercentFS -lt 80) -and ($D.PercentFS -GE 60)) | |
{ Write-Host "$($DeviceID) | $($FSGB) | $($PFS)" @Problem } | |
Else | |
{ Write-Host "$($DeviceID) | $($FSGB) | $($PFS)" @Bad } | |
} | |
} | |
# Get the color splats | |
Get-ColorSplat | |
$DiskInfo = Get-WmiObject Win32_LogicalDisk -ComputerName $ComputerName | | |
Select-Object -Property DeviceID, | |
@{Name="FreeSpaceGB";Expression={$_.Freespace/1GB}}, | |
@{Name="PercentFS";Expression={($_.FreeSpace/$_.Size)*100}} | |
If (!$PassThru) {Write-ColorOutput -DiskInfo $DiskInfo} | |
Else {Write-Output $DiskInfo} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment