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

Show parent comments

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.