#requires -version 2.0 <# ----------------------------------------------------------------------------- Script: demo-colorgraph.txt Version: 1.0 Author: Jeffery Hicks http://jdhitsolutions.com/blog http://twitter.com/JeffHicks http://www.ScriptingGeek.com Date: 12/9/2011 Keywords: Write-Host, Get-WMIObject, Group-Object Comments: "Those who forget to script are doomed to repeat their work." **************************************************************** * 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[]]$computers=@("computera","computerb","computerb") ) #get the current window width so that our lines will be proportional $Width = $Host.UI.RawUI.BufferSize.Width/2 $data=get-wmiobject -Class Win32_logicaldisk -filter "drivetype=3" -computer $computers #get length of longest computername so we can pad $longest=$data | select -ExpandProperty SystemName | sort Length | select -last 1 #group data by computername $groups=$Data | Group-Object -Property SystemName Clear-Host Write-Host ("`n{0} {1}`n" -f "Disk Drive Report",(Get-Date)) -ForegroundColor Yellow #iterate through each group object ForEach ($computer in $groups) { #define a collection of drives from the group object $Drives=$computer.group #iterate through each drive on each computer Foreach ($drive in $drives) { $FreeDividedSize=$drive.FreeSpace/$drive.Size [string]$PerFree="{0:P}" -f $FreeDividedSize [int]$FreePad=$Width*$FreeDividedSize $Used=$drive.Size - $drive.Freespace $UsedDividedSize=$used/$drive.Size [string]$perUsed="{0:P}" -f $UsedDividedSize [int]$UsedPad=$Width*$UsedDividedSize #not currently used [string]$UsedGB="{0:N2}GB " -f ($Used/1GB) [string]$FreeGB="{0:N2}GB " -f ($drive.FreeSpace/1GB) #this is the graph character [string]$g=[char]9608 [string]$freeGraph=$g*($FreePad) [string]$UsedGraph=$g*($UsedPad) write-host ("[{0}] {1} " -f $drive.systemname.PadRight($longest.length),$drive.DeviceID) -NoNewline write-host $freeGraph -ForegroundColor darkgreen -NoNewline write-host $UsedGraph -ForegroundColor red -NoNewline write-host (" {0} free " -f $PerFree) #insert a return between each drive write-host "`r" } #foreach drive #insert a blank line between computers if you want #Write-host "`n" } #foreach computer