Powershell and Automation
-
03-07-2019 - |
Question
I am just having a look at using Powershell, along with VI-Toolkit, to produce reports and charts showing VMware ESX performance and resource usage. So far, so good. But I am having trouble with doing the automation of chart objects (using OWC11.ChartSpace). As an example, I want to be able to control the x and y axes in terms of maximum values.
Anyone have any experience of this, or can refer me to some decent documentation?
Solution
OK, perhaps I didn't phrase the question very well, or perhaps there are just not that many developers using PowerShell and OWC on SO. Either way, I have done the usual load of reading and experimenting and have found my own answer. Here it is:
A Chart object in OWC has an Axes attribute - and the Axes has two elements - 1 for the Y-Axis and 1 for the X-Axis. My problem was how to access these and to set them.
$chartSpace = New-Object -Com OWC11.ChartSpace.11
$c = $chartSpace.Charts.Add()
([array] $c.Axes[0].HasTitle = "True"
([array] $c.Axes[0].Title.Caption = "My Y-Axis Caption"
([array] $c.Axes[1].HasTitle = "True"
([array] $c.Axes[1].Title.Caption = "Percentage"
([array] $c.Axes[1].Scaling.Maximum = 100
The key here was to cast the object in to an array so that I could then access the X and Y elements. After that it was dead easy.
It helped me, and perhams it will help someone else.