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
- #Usage: Get-WmiObject -computername Z002 Win32_LogicalDisk -filter "DriveType=3" | ./WPFDiskSpace.ps1
- #Note: Requires .NET 3.5, Visifire Charts (tested on v2.1.0), Powerboots (tested on v0.1)
- $libraryDir = Convert-Path (Resolve-Path "$ProfileDir\Libraries")
- [Void][Reflection.Assembly]::LoadFrom( (Convert-Path (Resolve-Path "$libraryDir\WPFVisifire.Charts.dll")) )
- if (!(Get-PSSnapin | ?{$_.name -eq 'PoshWpf'}))
- { Add-PsSnapin PoshWpf }
- New-BootsWindow -Async {
- $chart = New-Object Visifire.Charts.Chart
- $chart.Height = 500
- $chart.Width = 800
- $chart.watermark = $false
- $chart.Theme = "Theme2"
- $chart.View3D = $true
- $chart.BorderBrush = [System.Windows.Media.Brush]"Gray"
- $chart.CornerRadius = [System.Windows.CornerRadius]5
- $chart.BorderThickness = [System.Windows.Thickness]0.5
- $chart.AnimationEnabled = $false
- $ds1 = New-Object Visifire.Charts.DataSeries
- $ds1.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
- $ds1.LegendText = "UsedSpace"
- $ds1.LabelEnabled = $true
- #$ds1.LabelText = "#YValue"
- $ds2 = New-Object Visifire.Charts.DataSeries
- $ds2.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
- $ds2.LegendText = "FreeSpace"
- $ds2.LabelEnabled = $true
- #$ds2.LabelText = "#YValue"
- $ds2.RadiusX = 5
- $ds2.RadiusY = 5
- foreach ($disk in $input)
- {
- $pFree = $([int](([double]$disk.FreeSpace/[double]$disk.Size) * 100))
- $pUsed = $([int]((([double]$disk.Size - [double]$disk.FreeSpace)/[double]$disk.Size) * 100))
- $dp1 = new-object Visifire.Charts.DataPoint
- $dp1.AxisXLabel = ($disk.Name)
- $dp1.YValue = ([math]::round((([double]$disk.Size - [double]$disk.FreeSpace)/1GB),2))
- $dp1.LabelText = "$pUsed"
- $ds1.DataPoints.Add($dp1)
- $dp2 = new-object Visifire.Charts.DataPoint
- $dp2.YValue = ([math]::round(($disk.FreeSpace/1GB),2))
- $dp2.LabelText = "$pFree"
- $ds2.DataPoints.Add($dp2)
- }
- $chart.Series.Add($ds1)
- $chart.Series.Add($ds2)
- $chart
- } -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.
PowerShell Code Repository