Dynamic Columns -OnRender

I recently ran into a similar problem. The issue was that the variable was out of scope by the time the scriptblock was executed. I fixed this by first creating the scriptblock as a string and expanding the variable. After that, I passed the scriptblock to the -OnRender parameter like this:

$Fy = $year.FiscalYear
$ScriptBlockContent = @"
    `$Fy = `'$Fy`'
    "{0:C}" -f `$EventData.`$fy
"@
$scriptBlock = [ScriptBlock]::Create($ScriptBlockContent)
New-UDTableColumn -Property $Fy -Title $Fy -OnRender $Scriptblock

This way, the variable is properly expanded before being passed to the scriptblock.

Perhaps this could be solved by passing something to the scriptblock that contains the property name of the tablecolumn similar to $Eventdata.