Variable expansion inside -Content for scriptblock or -Id reflection

So, I was hoping to create a function that creates cards for multiple services/computers. The problem is I need to use a hack [scriptblock]::Create() to expand the variables inside the -Content portion of New-UDDynamic. Basically, it’s an ugly way to store persistent instance information for the code.

Is there a way within the Content portion to get the Id via reflection such that the code can be referenced more than once? Or can we a similar remote variable such as the $Using:var in Invoke-Expression?

Possible example:

function serviceCard {
param ($servername, $servicename)
  $key = "$Server-$ServiceName"
  $registration.Add($key,...)
  $Body = New-UDCardBody -id $key -Content {
    "$ServerName, $ServiceName" #this will currently return blank
    #method to Retrieve ID -> then lookup in table
    $key = $this.Id
    retrieveVariablesbyId $registration[$key]
    "$ServerName, $ServiceName"
    }
    New-UDCard -Body $Body
}

serviceCard -serverName servername -serviceName spooler
serviceCard -serverName servername -ServiceName stisvc
function serviceCard {
param ($ServerName,$ServiceName = 'spooler')


$serviceKey = "$ServerName ($ServiceName)"
$Header = New-UDCardHeader -Title "$serviceKey"

$fc = [scriptblock]::Create(@"
    New-UDButton -Variant text -Text "Start" -OnClick {
        Start-Service $ServiceName
        Show-UDToast -Message "Starting Service $serviceName on $ServerName" -Duration 5000
        Sync-UDElement -Id "$ServerName ($ServiceName)"
    }
    New-UDButton -Variant text -Text 'Stop' -OnClick {
        Stop-Service $serviceName
        Show-UDToast -Message "Stopping Service $serviceName on $ServerName" -Duration 5000
        Sync-UDElement -Id "$ServerName ($ServiceName)"
    }
    New-UDButton -Variant text -Text 'Restart' -OnClick {
        Restart-Service $ServiceName
        Show-UDToast -Message "Restarting Service $serviceName on $ServerName" -Duration 5000
        Sync-UDElement -Id "$ServerName ($ServiceName)"
    }
"@)

$Footer = New-UDCardFooter -Content $fc

$bc = [scriptblock]::Create(@"
New-UDDynamic -Id "$serviceKey" -Content {

    updateServiceStatus -serverName "$servername" -ServiceName "$serviceName"
  

    if (`$Session:serviceList["$serviceKey"]) {

        New-UDTable -Data (`$Session:serviceList["$serviceKey"].Service | Select-Object Status, Name,  DisplayName)  -Dense

    }    

    New-UDTypography -Text ("Last update: {0}" -f (`$Session:serviceList["$serviceKey"].LastUpdate) )

} -AutoRefresh -AutoRefreshInterval 10

"@)

#New-UDButton -Text 'Refresh' -OnClick { Sync-UDElement -Id "$serviceKey" }

$Body = New-UDCardBody -id "$serviceKey body" -Content $bc

New-UDCard -Body $Body -Header $Header -Footer $Footer

}

serviceCard -serverName servername -serviceName spooler
serviceCard -serverName servername -ServiceName stisvc
Product: PowerShell Universal
Version: 2.8