r/PowerShell • • Jan 19 '19

Universal Dashboard Sample

I posted yesterday about a Dashboard displaying information on our company's consultants. and a few guys/guyettes asked if I could share the code.Well, not exactly, but i managed to built something similar, without the company specifics.

https://github.com/PorreKaj/UD-Sample/

Simply install UniversalDashboard.Community 2.2.1 (requires .net 4.7.2), download the script and run it (well, don't just run stuff from the internet tho).It pulls data from AD so the ActiveDirectory module needs to be installed too.

note: To stop the dashboard, use Get-UDDashboard | Stop-UDDashboard

Once running, you can visit http://localhost:10001/ and see a dashboard with 3 pages.

(If that port is used, you can change the port number on the last line of the script.)

# Page 1 AD Dashboard, simple counters, donut chart, and a search box that's a bit more on the advanced side, search result will have a button that open a popup (modal) and show a bit more information on the account.(The search box is almost a direct copy of the one available on Ud marketplace - https://marketplace.universaldashboard.io/Dashboard/ud-activedirectory)

# Consultant dashboard.So this view is a bit more fun, but it relies on consultants being members of a group (in our case named "Consultants"), the name of the group can be changed on line 21 in the script.

# ServersSomeone out there asked if this could be used to monitor server metrics.Of course!, if you can get to the data with powershell, you can display it.

in this case, the docs specifically show how to do this - https://docs.universaldashboard.io/components/monitors

CPU and Memory monitors will be displayed for localhost, and for 2 servers you'll have to define in line 6 and 7.I didn't have time to do anything fancy, so these monitors only show data while the page is running, refresh and they'll start all over.

I tried to keep the code behind "segmented and neat" but it gets messy fast, and I ran out of time for today.

let me know how it goes.

Edit: forgot a block of code for the 'Employees by department' chart - ISE remembered the data for the chart so it never showed.

99 Upvotes

17 comments sorted by

View all comments

3

u/Zeniaz Jan 19 '19

So I'm trying to change Distribution of Employees by Department to By Office field instead. How would I go about doing that? I tried changing the "Department" fields to "Office" it doesn't seem to work.

5

u/PorreKaj Jan 19 '19

Oh my god, the codeblock for "ByDepartment" is completly missing :D

I updated the script on github.
Lines 91 through 113 covers the department chart.

For starters your can change "Department" to "Office" in the select statements on line 93 and 99.
That's all it would take to display the data.

Of course you'd want to rename the variables at some point, but now you can see the data you know if you mess it up. I know I've done that on almost all occasions.

Then, it would make sense to update the name of the properties in the object.
If you change the string 'Department' to 'Office' in the object on line 101-105.

$Counter = [PSCustomObject]@{
'Employees' = $($DepCount);
'Department' = $Department;
}

... you'd also have to change the name of the 'Labelproperty' to "Office", on line 250.
The chart specifically looks for the property defined in that.

| Out-UDChartData -DataProperty "Employees" -LabelProperty "Department"