r/PowerShell • • Nov 06 '17

FoxDeploy: Creating Glorious PowerShell Dashboards

https://foxdeploy.com/2017/11/06/glorious-powershell-dashboards/
170 Upvotes

46 comments sorted by

View all comments

3

u/JazDriveOmega Nov 07 '17

OK, I guess I'm stuck. Here is what I'm trying to do:

I export a bunch of data about my printers from my print server and SNMP (to pull toner data). I combine all that together into an array of PSObjects and export that to a JSON file. The object look like this:

{
    "Name":  "LOC-Printer-Color",
    "Type":  "HP Color LaserJet Pro M252dw",
    "Address":  "10.1.6.75",
    "Toner":  {
                  "Cyan":  19,
                  "Yellow":  21,
                  "Name":  "Toner Levels",
                  "Megnta":  26,
                  "Black":  34
              }
}

I want to create a Colum and Chart for each printer, displaying the levels of toner from the toner property.

This is what my dashboard code looks like:

Start-UDDashboard -port $i -Content {
    New-UDDashboard -NavbarLinks $NavBarLinks -Title "PowerShell Pro Tools Universal Dashboard" -NavBarColor '#011721' -NavBarFontColor "#CCEDFD" -BackgroundColor "#66C7F6" -FontColor "#011721" -Content {
        New-UDRow {
            $Printers = Get-Content .\printers.json | ConvertFrom-Json
            foreach ($Printer in $Printers) {
                $Toner = $Printer.Toner
                New-UDColumn -Size 3 {
                    New-UDChart -Title $Printer.Name -type Bar @Colors -RefreshInterval 3 -AutoRefresh -Verbose -Endpoint {
                        $Toner | Out-UDChartData -Verbose -LabelProperty "Name" -Dataset @(
                            New-UDChartDataset -DataProperty "Black" -Label "Black" -BackgroundColor "#080e1c" -HoverBackgroundColor "#080e1c"
                            New-UDChartDataset -DataProperty "Cyan" -Label "Cyan" -BackgroundColor "#42d4f4" -HoverBackgroundColor "#42d4f4"
                            New-UDChartDataset -DataProperty "Magenta" -Label "Magenta" -BackgroundColor "#ce3ef2" -HoverBackgroundColor "#ce3ef2"
                            New-UDChartDataset -DataProperty "Yellow" -Label "Yellow" -BackgroundColor "#f1d03e" -HoverBackgroundColor "#f1d03e"
                        )
                    }
                }
            }
        }
    }
}

but what I get back is a chart that looks like this:

https://imgur.com/a/QafiC

I'm not sure what I'm missing here. Is this some kind of a scoping issue? I've tried debugging in VS Code but it didn't really get me anywhere.

2

u/saGot3n Nov 08 '17

Try this. https://pastebin.com/5PWR4cn3 Use pscustom object to assign the data from the toner variable, that way the dataproperties can be called from new-udchatdataset. This is what I have been doing for data sets.