What's the proper way to write custom functions and pass them into the dashboard?

My apologies for the newbie-ish question; I just stumbled on to Powershell Universal Dashboard yesterday and first blush seems pretty cool!

I am trying to use this as a lightweight status display for a series of licensing servers that we have. As such, I need to call out to a program outside of Powershell, chop up the output, and drop it into the dashboard.

My problems are basically these:

  1. I have a custom function that returns the data I want but I cannot seem to use it inside of the dashboard. I have gotten external variables to work with New-UDDEndpointIntialization -Variable but using this for a function doesn’t seem to work. Here’s a little sample I whipped up that fails miserably:

function Test-Function {
Return 1

$Dashboard = New-UDDashboard -Title “This is a little test” -Content {
New-UDEndpointInitialization -Function “Test-Function”
New-UDCard -Title “The Title” -Endpoint {Test-Function}
Start-UDDashboard -Port 80 -Dashboard $Dashboard -AutoReload

What am I doing wrong?

I am getting something like this inside the card:

The term ‘Test-Function’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

  1. From a higher level, I am looking for advice on approaches to bringing this information to life in PUD. I started out setting up an array of all of my variables for each license service in an array and then building out the dashboard. I ran into problems getting data into the dashboard from that powershell so re-doubled effort on reading the documentation and decided to make a usable function that I could call from within the dashboard elements and spit out some text. If you had to call out to a program, parse and slice the returned data, to display within UD (and repeat that same process multiple times), how would you approach it?

Thanks for listening to the newb questions!


P.S. The documentation is great and looks polished but I think it fails because it does not address most functionality in context. For example, I found the New-UDEndpointInitialization documentation and have tried calling that inside and outside of the dashboard I’m creating, and I have tried calling the initialized function I am using multiple ways; I still don’t truly know what the correct way might be in either case.

Sorry that the documentation is a bit lacking.I’m always trying to improve it so I guess I’ll have to revisit this tid bit.

New-UDEndpointInitiailization returns an object that you will want to pass to the -EndpointInitialization parameter for New-UDDashboard.

function Test-Function {
Return 1

$EI = New-UDEndpointInitialization -Function “Test-Function”
$Dashboard = New-UDDashboard -Title “This is a little test” -Content {

New-UDCard -Title “The Title” -Endpoint {Test-Function}
} -EndpointInitialization $EI
Start-UDDashboard -Port 80 -Dashboard $Dashboard -AutoReload

You should be able to do the same for your variables.

$MyVariable = 1
$MyVariable2 = 2
$EI = New-UDEndpointInitialization -Variable @('MyVariable', 'MyVariable2')
$Dashboard = New-UDDashboard -Title “This is a little test” -Content {

New-UDCard -Title “The Title” -Endpoint {$MyVariable}
New-UDCard -Title “The Title” -Endpoint {$MyVariable2}
} -EndpointInitialization $EI
Start-UDDashboard -Port 80 -Dashboard $Dashboard -AutoReload

Wonderfully complete and quick reply, Adam! Thank you so much!

I would be happy to contribute some examples too. Presumably that’s just a pull request to the docs project?

Thanks for the work on this cool and really useful tool!

Yeah sure thing! And if you are feeling up to it the docs repo is here: https://github.com/adamdriscoll/universal-dashboard-documentation/

I had this issue the other day when trying to wrap my head around it. I was able to dig through some of your codebase and found some examples that showed it being used like this.

Documentation is a hard thing to keep accurate and up-to-date, especially on such a large module.

Is the syntax the same if the function would return a string-value?
as when i change the returnvalue to ‘Test 1’, nothing is returned in the GUI

Sorry to hijack this thread.

@adam - I do not have any issue declaring the variable independently to EndpointInitialization, but not through a foreach object. How do you pass variable from a foreach object? Something like below.

Get-Content "xxxxx" | Foreach-Object {
    $a = $_.Split(",")[0]
    $b = xxxx

    if ($a -eq $b) {

      $var = True
$init = New-UDEndpointInitialization -Variable @("var")

I checked all var in the foreach to a UDcard, output are correct. I hope you can enlighten me on how to correctly do this. Thanks!

Let me be a little clear, with a simple string it worked. What I am trying to achieve is to ensure condition of “$user” or “$ClaimsPrincipal.Identity.Name” is matching with $a. I was able to run and display all these var in a UDcard. But EndpointInit did not capture the var.

We do not have the a dedicated ADgroup for users, so I need to load these users manually with their primarySID or Name and cross-check with their authentication sessions. Any advise?

I have got it working using this.

if ($ClaimsPrincipal.Identity.Name -eq $SID)