# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009 # # NAME: Drivereport.ps1 # # AUTHOR: Jeffery Hicks , JDH Information Technology Solutions # DATE : 10/13/2009 # # COMMENT: display colored "bar" charts for fixed disk usage. # **************************************************************** # * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * # * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * # * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * # * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * # **************************************************************** # # ============================================================================================== Param ([string]$computername=$env:computername, [Management.Automation.PSCredential]$credential) Trap { #if an exception occurs, display a warning message and bail Write-Warning "There was a problem getting WMI information from $computername." Write-Warning $_.Exception.Message Return } if ($credential) { $drives=Get-WmiObject win32_logicaldisk -Filter "drivetype=3" -ComputerName $computername -Credential $credential -ea Stop } else { $drives=Get-WmiObject win32_logicaldisk -Filter "drivetype=3" -ComputerName $computername -ea Stop } Write-Host $computername.ToUpper() foreach ($drive in $drives) { [int64]$size=$drive.size [int64]$free=$drive.Freespace [int]$bar=($free/$size) *100 $used=($size-$free)/$size if ($bar -ge 80) { $color="Green" } elseif ($bar -ge 60) { $color="DarkGreen" } elseif ($bar -ge 40) { $color="Yellow" } elseif ($bar -ge 20 ) { $color="Magenta" } else { $color="Red" } $data="{0} {1:N2}GB free {2} {3:P2}" -f $drive.DeviceiD,($free/1GB),(" " * $bar),$used Write-Host $data -BackgroundColor $color -ForegroundColor "black" } #end ForEach