PoshCode Logo PowerShell Code Repository

WPFDiskSpace (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/992"></script>download | new post

Uses Powerboots and Visifire to display a WPF graph of disk space including percent used and free

  1. #Usage: Get-WmiObject -computername Z002 Win32_LogicalDisk -filter "DriveType=3" | ./WPFDiskSpace.ps1
  2. #Note: Requires .NET 3.5, Visifire Charts (tested on v2.1.0), Powerboots (tested on v0.1)
  3.  
  4. $libraryDir = Convert-Path (Resolve-Path "$ProfileDir\Libraries")
  5. [Void][Reflection.Assembly]::LoadFrom( (Convert-Path (Resolve-Path "$libraryDir\WPFVisifire.Charts.dll")) )
  6.  
  7. if (!(Get-PSSnapin | ?{$_.name -eq 'PoshWpf'}))
  8. { Add-PsSnapin PoshWpf }
  9.  
  10. New-BootsWindow -Async {
  11.     $chart = New-Object Visifire.Charts.Chart
  12.     $chart.Height = 500
  13.     $chart.Width = 800
  14.     $chart.watermark = $false
  15.     $chart.Theme = "Theme2"
  16.     $chart.View3D = $true
  17.     $chart.BorderBrush = [System.Windows.Media.Brush]"Gray"
  18.     $chart.CornerRadius = [System.Windows.CornerRadius]5
  19.     $chart.BorderThickness = [System.Windows.Thickness]0.5
  20.     $chart.AnimationEnabled = $false
  21.  
  22.     $ds1 = New-Object Visifire.Charts.DataSeries
  23.     $ds1.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
  24.     $ds1.LegendText = "UsedSpace"
  25.     $ds1.LabelEnabled = $true
  26.     #$ds1.LabelText = "#YValue"
  27.  
  28.     $ds2 = New-Object Visifire.Charts.DataSeries
  29.     $ds2.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
  30.     $ds2.LegendText = "FreeSpace"
  31.     $ds2.LabelEnabled = $true
  32.     #$ds2.LabelText = "#YValue"
  33.     $ds2.RadiusX = 5
  34.     $ds2.RadiusY = 5
  35.  
  36.     foreach ($disk in $input)
  37.     {
  38.  
  39.     $pFree = $([int](([double]$disk.FreeSpace/[double]$disk.Size) * 100))
  40.     $pUsed = $([int]((([double]$disk.Size - [double]$disk.FreeSpace)/[double]$disk.Size) * 100))
  41.     $dp1 = new-object Visifire.Charts.DataPoint
  42.     $dp1.AxisXLabel = ($disk.Name)
  43.     $dp1.YValue = ([math]::round((([double]$disk.Size - [double]$disk.FreeSpace)/1GB),2))
  44.     $dp1.LabelText = "$pUsed"
  45.     $ds1.DataPoints.Add($dp1)
  46.  
  47.     $dp2 = new-object Visifire.Charts.DataPoint
  48.     $dp2.YValue = ([math]::round(($disk.FreeSpace/1GB),2))
  49.     $dp2.LabelText = "$pFree"
  50.     $ds2.DataPoints.Add($dp2)
  51.  
  52.  
  53.     }  
  54.     $chart.Series.Add($ds1)
  55.     $chart.Series.Add($ds2)
  56.  
  57.     $chart
  58. } -Title "Disk Space"

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me