Dynamically named Cached variable within endpoint

Good evening,

I am attempting to dynamically create a variable within an endpoint based on a CSV and then call the variable from the Dashboard.

The variable will be created at “New-Variable -Name “$($server.name)fullname” -Value $server.name” but must be added to the $Cache: scope so it can be called from New-UDParagraph -Text REFERENCE_TO_CACHED_VARIABLE.

How would I create a variable “$Server1fullname” and call “$Cache:Server1fullname”

$db = new-UDDashboard -Title "Dashboard 2.0" -Content {

New-udrow -Columns {
    New-UDColumn -size 3 -Endpoint {
        New-UDCard -id "test" -Title "test card" -BackgroundColor REFERENCE_TO_CACHED_VARIABLE -Endpoint {
            New-UDParagraph -Text REFERENCE_TO_CACHED_VARIABLE
        }
    } -AutoRefresh -RefreshInterval 60

}

}

$Cache:BGpass = “#93ec71

$Schedule_Server_Name = New-UDEndpointSchedule -Every 1 -Minute

$Endpoint_Server_Name = New-UDEndpoint -Schedule $Schedule_Server_Name -Endpoint {

$Masterlist = Import-Csv "C:\UniversalDashboard\ServerConfig.csv"

Remove-Variable -Name *background
Remove-Variable -Name *services

foreach ($server in $Masterlist) {

    New-Variable -Name "$($server.name)fullname" -Value $server.name
    New-Variable -Name "$($server.name)background" -Value $Cache:BGpass
}

}

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $db -Port 10000 -Endpoint $Endpoint_Server_Name -AutoReload

New-Variable has a -scope parameter, maybe that can be used?

Maybe try to explaining the end result you are attempting to obtain.

I’m a little confused by and the need to extract that data into variables.
$Masterlist = Import-Csv "C:\UniversalDashboard\ServerConfig.csv"

You have an array of objects at this point, so not sure the need for assigning to a variable.

$Masterlist | get-member will give you the properties.

I would try using the data properties directly. Like $Masterlist.propertyname or $_.propertyname

Good evening,

You are correct that $Server1fullname may not need a variable as it is an array. I may go that route.

However, $Server1background I believe needs a variable. Pass or fail will be determined by some logic and then assigned to the variable. This will then determine the background of the card for RED or GREEN.
I am trying to get New-UDCard -Title “Test” -BackgroundColor $Server1background to hold the RED or Green value.

Good evening,

New-Variable -Name “$($server.name)fullname” -Value server.name -Scope Global New-Variable -Name "($server.name)background" -Value $BGpass -Scope Global

And then referencing:

-BackgroundColor $Global:Server1background

has not yielded the expected results. It seems to be blank at this time. I think I’m missing something simple on this one. I’m currently digging into debugging to find where it misses the mark.