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

1

u/Gotcha007 Nov 10 '17

2 Questions.

  • Is there a way to pass a parameter to the page when you call it?

  • Also, I'm using the input field and New-UDInputAction -Content to show my Dashboard. The input field takes a computer name and the dashboard show the cpu activity for that computer. The issue is that in order to show again the input field I have to refresh the page. Is there another way to do it?

1

u/saGot3n Nov 10 '17

I think dynamic pages is what you are looking for, I am looking into this right now and not having any luck. From his documentation it should be fairly simple, yet when I do it i just get a black page. Here I have my homepage with just the user input field, then when they put in the pc name and submit, the dynamic page should show up with the user input field at the top and then a card with the pcname. This is just a simple page to test the functionality, but all I get is a blank page.

$Homepage = New-UDPage -Name "HomePage" -Icon Home -Content {
    New-UDRow {
        New-UDColumn -Size 4 -Content{
        }
        New-UdColumn -Size 4 -Content {
            New-UDInput -Title "Computer Name" @colors -Endpoint {
                param($COMPUTER)
                New-UDInputAction -RedirectUrl "/dynamic/$Computer"
            }
        }
        New-UDColumn -Size 4 -Content{
        }
    }
}

$dynamic = New-UDPage -Url "/dynamic/:computername" -Endpoint {
    param($computername)
    new-udrow {
        New-UDColumn -Size 12 -Content{
            New-UDRow {
                New-UdColumn -Size 12 -Content {
                New-UDInput -Title "Computer Name" @colors -Endpoint {
                        param($COMPUTER)
                    New-UDInputAction -RedirectUrl "/dynamic/$Computer"
                    }
                }
            }
            New-UDRow {
                New-UDCard -Title "Results" -Content "$computername"
            }
        }
    }
}

1

u/tharagz08 Nov 21 '17

Have you had any luck with this? Being able to pass a parameter in is pretty critical in being able to make this a solid dashboard tool for me.

1

u/saGot3n Nov 21 '17

Yes I got it to work, using it for a portal for our service desk to get PC info/stats of the users pc via computername. Im on vacation till till monday and can share the code with ya.

1

u/tharagz08 Nov 22 '17

That would be outstanding, thank you!

1

u/saGot3n Nov 27 '17

Here is the basics of what I have, i put in part of the template from the main example from the author.

$Homepage = New-UDPage -Name "HomePage" -Icon Home -Content {
    New-UDRow {
        New-UDColumn -Size 4 -Content{
        }
        New-UdColumn -Size 4 -Content {
            New-UDInput -Title "Computer Name" @colors -Endpoint {
            param($COMPUTER)
            New-UDInputAction -RedirectUrl "/dynamic/$Computer"
            }
        }
        New-UDColumn -Size 4 -Content{
        }
    }
}

$dynamic = New-UDPage -Url "/dynamic/:computername" -Endpoint {
param($computername)
    new-udrow {
        New-UDColumn -Size 12 -Content{
            New-UDRow {
                New-UdColumn -Size 8 -Content {
                    New-UdTable -Title "Server Information" -Headers @(" ", " ") @colors -Endpoint {
                            @{
                                'Computer Name' = $computername
                                'Operating System' = (Get-wmiobject -computername $computername -ClassName Win32_OperatingSystem).Caption
                                'Total Disk Space (C:)' = (Get-wmiobject -computername $computername -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
                                'Free Disk Space (C:)' = (Get-wmiobject -computername $computername -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }
                            }.GetEnumerator() | Out-UDTableData -Property @("Name", "Value")
                    }
                }
                New-UdColumn -Size 4 -Content {
                    New-UDInput -Title "Computer Name" @colors -Endpoint {
                        param($COMPUTER)
                        New-UDInputAction -RedirectUrl "/dynamic/$Computer"
                    }
                }
            }
            New-UDRow {
                New-UDColumn -Size 3 {
                    New-UdMonitor -Title "CPU (% processor time)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63' @colors  -Endpoint {
                        try {
                            get-counter -computername $computername '\Processor(_Total)\% Processor Time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            1 | Out-UDMonitorData
                        }
                    }
                }
            New-UDColumn -Size 3 {
                    New-UdMonitor -Title "Memory (% in use)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63' @colors  -Endpoint {
                        try {
                            get-counter -computername $computername '\memory\% committed bytes in use' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            1 | Out-UDMonitorData
                        }
                    }
                }
            New-UDColumn -Size 3 {
                    New-UdMonitor -Title "Network (IO Read Bytes/sec)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63' @colors  -Endpoint {
                        try {
                            get-counter -computername $computername '\Process(_Total)\IO Read Bytes/sec' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            1 | Out-UDMonitorData
                        }
                    }
                }
            New-UDColumn -Size 3 {
                    New-UdMonitor -Title "Disk (% disk time)" -Type Line -DataPointHistory 20 -RefreshInterval 5 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63' @colors  -Endpoint {
                        try {
                            get-counter -computername $computername '\physicaldisk(_total)\% disk time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue | Out-UDMonitorData
                        }
                        catch {
                            1 | Out-UDMonitorData
                        }
                    }
                }
            }
        }
    }
}

Start-UDDashboard -Content { 
    New-UDDashboard -NavbarLinks $NavBarLinks -Title "Dashboard" -NavBarColor '#FF1c1c1c' -NavBarFontColor "#FF55b3ff" -BackgroundColor "#FF333333" -FontColor "#FFFFFFF" -Pages @(
        $HOMEPAGE
    ) 
}

1

u/tharagz08 Nov 27 '17

Dynamic pages are exactly what I was looking for. I think I'm running into the same problem you were originally though.

After inputting computer name I am being brought to a blank page. How do you call on the script you've stored in $Dynamic? From what I can tell your script is just starting up a new dashboard with the $HOMEPAGE variable, then redirecting that to the "/dynamic/$Computer" URL but none of the queries are being called on from within the $Dynamic variable.

1

u/saGot3n Nov 28 '17

Whooooops, replace that last part of the script with this, also remove the @colors from the script unless you have that setup.

Start-UDDashboard -Content { 
    New-UDDashboard -NavbarLinks $NavBarLinks -Title "Dashboard" -NavBarColor '#FF1c1c1c' -NavBarFontColor "#FF55b3ff" -BackgroundColor "#FF333333" -FontColor "#FFFFFFF" -Pages @(
        $HOMEPAGE,
        $dynamic
    ) 
}

1

u/tharagz08 Nov 28 '17

That got it goin! What a simple fix. I did end up getting it to work as well but I took a different approach. Instead of calling on two variables I used one and first built the page for user input, then once the input was received I built the second page and redirected to it. In the end probably the same results and same speed.

Have you experimented with multiple parameters yet? In my environment we deal with multiple domains where we do not have a trust setup. To work around this we store credentials in secure strings, encrypt them and then call on them as needed for each domain. Being able to pass multiple variables into these pages would make it possible to work around this limitation in my use case.

1

u/saGot3n Nov 28 '17

Awesome, glad you got it working! I havent had the need to do multiple variables, but I would assume its possible, or on your user input fields have one for each domain with a static domain variable so if a user uses domain1 for input the dynamic page would go to the dynamic page for domain1 and the same for domain2, it would go to the dynamic page you built for domain2.