Oct 182010

I have been investigating using Microsoft Chart Controls for Microsoft .NET Framework 3.5 to create some nice looking images in my Powershell reporting script. I am in the early stage but here is an initial snip-it of how powerful this can be.

Once I finish my report script I will post it for everyone to enjoy.

# -----------------------------------------------------------------------------------------------------------
### Script Name - charting for vcenter object demo
### Author - David Owen
### Description - this script gathers the VM objects and displays them in graph format.
# connect to you VC or ESX server
Connect-VIServer -Server "your server"
# gather statistics to be used in the graph
$vms = Get-VM -Name *io*
$vms1 = Get-VM -Name *4
# create chart object
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 350
$Chart.Height = 250
$Chart.Left = 25
$Chart.Top = 15
# create a chart area to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
# add data to chart
$conts = @{"Total of vms with io in the name" = $vms.count; "number of VMs with 4 in the name" = $vms1.count}
$Chart.Series["Data"].Points.DataBindXY($conts.Keys, $conts.Values)
# set chart type
$Chart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
# set chart options
$Chart.Series["Data"]["PieLabelStyle"] = "Outside"
$Chart.Series["Data"]["PieLineColor"] = "Black"
$Chart.Series["Data"]["PieDrawingStyle"] = "Concave"
($Chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true
invoke-item "$pwd\myChart1.gif"
Disconnect-VIServer -Force -WarningAction SilentlyContinue

Here are some example charts.

I produced the pie chard just using get-vm as the data source.

As you can see you can do some real cool treading stats with this .net extension. I’m not a .net developer and all the examples are in .net so its a slow process but the basic charts I am producing are relay cool and will fit nicely into reports.

Things like up-time statistics and resource processes easy accessible through the VMware APIs that normally you can only get from the viclient are now totally customizable into you own format etc to fit your needs.

Post to Twitter

Twitter links powered by Tweet This v1.8.3, a WordPress plugin for Twitter.