JuanC Posted February 2, 2007 Report Share Posted February 2, 2007 There are some cmdlet parameters in PowerGadgets where we support powershell script blocks, although its support may not be obvious. We think they enable important scenarios so I will try to describe them here. Parameters that normally specify fields: In out-chart (or out-map) the -values and -label parameters allow you to specify one or more fields to be plotted and the field to be used as labels. Both parameters support scriptblocks which allow the following: ps | out-chart -values {$_.WorkingSet/$_.Handles}ps | out-chart -values @{Expression={$_.WorkingSet/$_.Handles};Name="WorkingSet per Handle"}ps | out-chart -values CPU -label {$_.ProcessName + "-" + $_.ID} Note that the expression will also be used as the series title, to fix this you can use trick in the second line where a hashtable is created with 2 elements, the expression and the name to be used, you may need to resize the chart vertically to see the labels in the third sample. Almost any out-gauge parameter Because out-gauge is normally used to display one value, we can use additional fields in the data for almost any parameter supported by out-gauge, e.g. imagine you want a digital panel that changes color when the displayed value is bigger than a specified value. RandomData.ps1 $random = new-object System.Random$value = [system.Int32] ($random.NextDouble() * 20);$prevValue = [system.Int32] ($random.NextDouble() * 20);$color = "Green"if ($value -lt 8) { $color = "Red"} $obj = new-object System.objectadd-member -inputobject $obj -membertype NoteProperty -Name Sales -value $valueadd-member -inputobject $obj -membertype NoteProperty -Name Color -value $color add-member -inputobject $obj -membertype NoteProperty -Name PrevSales -value $prevValue $obj This script returns an object with 3 properties the value to be displayed and a color property which depends on the value (PrevSales will be used in our next sample), you can then use this data as follows .\Randomdata.ps1 | out-gauge -type digital -value Sales -appearance_color {$_.Color} -refresh 0:0:2.\Randomdata.ps1 | out-gauge -type radial -value Sales -mainindicator_color {$_.Color} -refresh 0:0:2 /TeamBlogImages/ScriptBlocksupportinPowerGadgets_D4C/image02.png /TeamBlogImages/ScriptBlocksupportinPowerGadgets_D4C/image04.png A similar scenario would be to show a value for the current year/month in a gauge while at the same time showing the value for the previous year/month as a reference. .\Randomdata.ps1 | out-gauge -type radial -value Sales -mainscale_indicators_add marker -mainscale_indicators_1_size 0.75 -mainscale_indicators_1_value {$_.PrevSales} /TeamBlogImages/ScriptBlocksupportinPowerGadgets_D4C/image0_thumb1.png In this case we are adding an indicator to the main scale and then settings its size to be 0.75, the value property for this marker will be the PrevSales property returned by our script. If you want to customize this further you would probably want to use our template editor (out-gauge -config), create a template with an extra indicator, set any of its properties and then use this template as follows .\Randomdata.ps1 | out-gauge -type radial -value Sales -template ExtraIndicator -mainscale_indicators_1_value {$_.PrevSales} Please feel free to post any questions or suggestions as comments or in the forums, most of these features are the direct result of your feedback. JuanC Link to comment Share on other sites More sharing options...
Anonymous Posted February 9, 2007 Report Share Posted February 9, 2007 In a previous post we exposed how the out-chart and out-map cmdlets support scriptblocks in parameters Link to comment Share on other sites More sharing options...
Recommended Posts