Grid content in $session variable @()

Try to do something like this:

$session:mygridvar=@()
$myrow="" | select-object field0,field1,field2,field3,field4

$myrow.field0=“A”
$myrow.field1=“B”
$myrow.field2=“C”
$myrow.field3=“D”
$myrow.field4=“E”
$session:mygridvar+=$myrow

$myrow.field0=“1”
$myrow.field1=“2”
$myrow.field2=“3”
$myrow.field3=“4”
$myrow.field4=“5”
$session:mygridvar+=$myrow

New-UDGrid -ID ‘ABC’ -Title “ABC” -Headers @(“1”, “2”, “3”,“4”, “5”) -Properties @(“field0”, “field1”,“field2”,“field3”, “field4”) -Endpoint {
$session:mygridvar | Out-UDGridData
}

everything is working fine as Long as i do not use session context.
$mygridvar=@() -> works fine
$session:mygridvar=@() -> get error:

Exception calling “Invoke” with “0” argument(s): “Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named ‘op_Addition’.”

But I Need session context to work with $mygridvar in other places …
Can someone please help me?

Hi @Fabian I have only used the $session variable once in a dashboard project. I have posted it in the show off section, but I uploaded a copy of it here:-


Hopefully this will help you out

I think I found a Workaround …

first work with $mygridvar and PSCustomObject instead of select-object.
(not in session context) At the end put the result into a $session:variable:

$mygridvar | Out-UDGridData
$session:mymemoryvar=$mygridvar

This seems to work … Just changing my source-code (lot of work …)

Hey @Fabian so glad you got the solution working…the nivo chart heatmap had me stumped for a longtime. Least you know how to work it now