r/PowerShell • u/1RedOne • Nov 06 '17
FoxDeploy: Creating Glorious PowerShell Dashboards
https://foxdeploy.com/2017/11/06/glorious-powershell-dashboards/6
u/iisdmitch Nov 06 '17
So I want to test this out but after the module is installed I do not get the popup screen that is supposed to appear according to the guide. The module is definitely installed.
6
u/1RedOne Nov 06 '17
Oh my mistake, here's what you should do:
install the module
download Adam's sample dashboard
run it, which should launch the dashboard in your browser and show you the prompt
Thanks for the heads up, I've fixed it on the post too as well.
4
u/saGot3n Nov 08 '17
Doing great so far! Easy stuff coming along nicely, next to work on some of the harder stuff. Most of the data is refreshed daily in a seperate PS1 file and the data is imported from the CSV's.
1
1
3
u/IT_dude_101010 Nov 06 '17
2
u/1RedOne Nov 06 '17
I know dude they're so awesome. I thought about just deleting all of my old guides, these are so good.
And the library Adam based it in has some gorgeous other components. This will just get better and better!
4
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:
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/1RedOne Nov 07 '17
First off, WOW you went way farther than I've gotten so far.
Second, can you share that printers.json file so I can try to play with it?
2
u/JazDriveOmega Nov 07 '17
Thanks! Its funny, a while back I built a tool that used Firebase and AgularFire to generate a dashboard, not unlike this one. This is obviously way easier since I don't have to be the one to keep up with whatever underlying web technology is running the whole thing :P
Here is my JSON file: https://pastebin.com/HNfJEU5R
I've also thought about trying to dump each toner out as a json file and try to work with them that way. But I think I just run in to the same issue. I think once you get down to the Endpoint on New-UDChart, you lose the object from the loop and I'm not sure if you can pass it along.
1
u/tharagz08 Nov 21 '17
Were you able to get your JSon file to be read properly? I am running into the same issue. I wasn't able to get far using your file either.
1
u/JazDriveOmega Nov 22 '17
Yes! It ended up being a bug in UD its self. There were a few bugs actually, but they have all been resolved now.
I've posted the end result on github: https://github.com/AmazingWizard/UD-PrinterDashboard
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.
5
u/xsdc Nov 07 '17
My one complaint with the idea of this being a paid thing is I can't dig in to the code and butcher it.
1
Nov 07 '17
Yeah I wish it was open source. It needs more options to customise it. Things like conditional formatting on tables, spark lines, more chart types etc
4
Nov 08 '17
Hey, everybody! Adam here.
I'm happy to answer any questions. If you are looking for more information, here are some good resources.
1
u/Fischfreund Nov 10 '17
Hi, any way to authenticate users?
1
Nov 10 '17
This functionality is in progress: https://github.com/adamdriscoll/poshprotools/issues/29
1
u/Fischfreund Nov 10 '17
Hi,
any way to define min and max values for the
New-UDMonitorcmdlet? I created a new Monitor likeNew-UdMonitor -Title "Ping New Zealand" -Type Line -DataPointHistory 20 -RefreshInterval 2 -ChartBackgroundColor '#80FF6B63' -ChartBorderColor '#FFFF6B63' -Endpoint { Test-Connection wellington.nz.com -Count 1 | Select-Object -ExpandProperty ResponseTime | Out-UDMonitorDataAnd it obviously shows like this: https://i.imgur.com/ARiMYvq.png
Can I set the Y axis to 0?
2
Nov 10 '17
You can pass ChartJS options into the New-UDChart cmdlet. Try the options parameter like this:
-Options @{ scales = @{ yAxes = @( @{ ticks = @{ beginAtZero = $true } } ) } }1
u/nittanygeek Nov 22 '17
This doesn't seem to work with New-UDMonitor. I'm getting the same results as /u/Fischfreund. Any fix for this?
1
1
u/RedditRo55 Nov 13 '17
Will this output an image file like .jpg or .png? This would probably be a requirement for us.
2
u/1RedOne Nov 13 '17
No, it spins up a webserver and renders in HTML / JavaScript. You could script up an ie object and navigate to the page them screenshot it though. I've covered that on FoxDeploy If you'd like samples
2
u/IDA_noob Nov 07 '17
Shit man. I have work to do. Now I have to stop all of that and play with this.
2
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.
10
u/1RedOne Nov 06 '17
Hi guys!
I did a deep dive into how to make your own dashboards using Adam Driscoll's very new 'PowerShell Universal Dashboards' PowerShell module.
Simply run a quick:
And then follow along to make one in your environment!