PoshCode Logo PowerShell Code Repository

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

Uses Powerboots, Visifire and SQLPSX to Display a WPF graph of SQL Server database data and log file space

  1. #Usage: Get-SqlDatabase 'Z002\Sql2k8' | where {$_.name -like "pubs*"} | ./WPFDbSpace.ps1
  2. #Note: Requires .NET 3.5, Visifire Charts (tested on v2.1.0), Powerboots (tested on v0.1), and SQLPSX (tested on v1.5)
  3.  
  4. $libraryDir = Convert-Path (Resolve-Path "$ProfileDir\Libraries")
  5. [Void][Reflection.Assembly]::LoadFrom( (Convert-Path (Resolve-Path "$libraryDir\WPFVisifire.Charts.dll")) )
  6. . $libraryDir\LibrarySmo.ps1
  7.  
  8. if (!(Get-PSSnapin | ?{$_.name -eq 'PoshWpf'}))
  9. { Add-PsSnapin PoshWpf }
  10.  
  11. New-BootsWindow -Async {
  12.     $chart = New-Object Visifire.Charts.Chart
  13.     $chart.Height = 500
  14.     $chart.Width = 800
  15.     $chart.watermark = $false
  16.     $chart.Theme = "Theme2"
  17.     $chart.View3D = $true
  18.     $chart.BorderBrush = [System.Windows.Media.Brush]"Gray"
  19.     $chart.CornerRadius = [System.Windows.CornerRadius]5
  20.     $chart.BorderThickness = [System.Windows.Thickness]0.5
  21.     $chart.AnimationEnabled = $false
  22.  
  23.     $ds1 = New-Object Visifire.Charts.DataSeries
  24.     $ds1.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
  25.     $ds1.LegendText = "UsedSpace"
  26.     $ds1.LabelEnabled = $true
  27.     $ds1.LabelText = "#YValue"
  28.  
  29.     $ds2 = New-Object Visifire.Charts.DataSeries
  30.     $ds2.RenderAs = [Visifire.Charts.RenderAs]"StackedBar"
  31.     $ds2.LegendText = "FreeSpace"
  32.     $ds2.LabelEnabled = $true
  33.     $ds2.LabelText = "#YValue"
  34.     $ds2.RadiusX = 5
  35.     $ds2.RadiusY = 5
  36.  
  37.     foreach ($db in $input)
  38.     {
  39.         if ($db.GetType().Name -ne 'Database')
  40.         { throw 'Input must be Database object' }
  41.        
  42.         foreach ($file in Get-SqlDataFile $db)
  43.         {
  44.             $dp1 = new-object Visifire.Charts.DataPoint
  45.             $dp1.AxisXLabel = ($db.Name + '.' + $file.Name)
  46.             $dp1.YValue = ([int]($file.UsedSpace/1KB))
  47.             $ds1.DataPoints.Add($dp1)
  48.  
  49.             $dp2 = new-object Visifire.Charts.DataPoint
  50.             $dp2.YValue = ([int](($file.Size - $file.UsedSpace)/1KB))
  51.             $ds2.DataPoints.Add($dp2)
  52.         }
  53.  
  54.         $log = Get-SqlLogFile $db
  55.  
  56.         $dp3 = new-object Visifire.Charts.DataPoint
  57.         $dp3.AxisXLabel = ($db.Name + '.' + $log.Name)
  58.         $dp3.YValue = ([int]($log.UsedSpace/1KB))
  59.         $ds1.DataPoints.Add($dp3)
  60.  
  61.         $dp4 = new-object Visifire.Charts.DataPoint
  62.         $dp4.YValue = ([int](($log.Size - $log.UsedSpace)/1KB))
  63.         $ds2.DataPoints.Add($dp4)
  64.  
  65.  
  66.     }  
  67.     $chart.Series.Add($ds1)
  68.     $chart.Series.Add($ds2)
  69.  
  70.     $chart
  71. } -Title "Database 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