EventData in foreach

I was trying to use $EventData inside a foreach loop to render image based on Url hoping it would do the trick but for some reason it does not work/render. Probably I’m using it incorrectly.

foreach ($colname in $clouddt.Columns) {
       $colname = $colname.ColumnName
       if ($colname -eq "Device") {
             New-UDTableColumn -Property $colname
       } else {
             New-UDTableColumn -Property $colname -Render {
                   New-UDImage -Url $EventData.$colname
          }
     }
}
Product: PowerShell Universal
Version: 1.5.8
Framework: Latest

it’s hard to debug and trying to help if we can’t reproduce the issue’ please give us some mocked demo code to work with.

Hey @AlonGvili

Here is the full script. Is all based on API JSON return and stored within a DataTable (below).

Device                    SSL Security Check                    SSL Certificate Sensor
------                    -----------------------------         ---------------------------------
[Webserver]          http://localhost:5000/img/down.png         http://localhost:5000/img/down.png
[Webserver]          http://localhost:5000/img/warning.png      http://localhost:5000/img/down.png
[Webserver]          http://localhost:5000/img/warning.png      http://localhost:5000/img/down.png
[Webserver]          http://localhost:5000/img/warning.png      http://localhost:5000/img/up.png
[Webserver]          http://localhost:5000/img/warning.png      http://localhost:5000/img/down.png
    $clouddt = New-Object System.Data.DataTable
    $clouddt.Clear()
    $clouddt.Columns.Add("Device")

    $cloudsensors = $Global:cloudapidata.sensors | Where {$_.group -eq "SSL"}
    foreach ($cloudsensorrow in $cloudsensors) {
        if (!($clouddt.Columns.Contains($cloudsensorrow.sensor))) {
            $clouddt.Columns.Add("$($cloudsensorrow.sensor)")
        }
    }

    foreach ($cloudsensor in $cloudsensors) {
        $clouddr = $clouddt.NewRow()
        $clouddr["Device"] = $cloudsensor.device

        $clouddevices = $Global:cloudapidata.sensors | Where {$_.group -eq "SSL" -and $_.device -eq $cloudsensor.device}
        
        if (!($clouddt.Select("Device = '" + $cloudsensor.device + "'"))) {
            foreach ($clouddevice in $clouddevices) {
                if($clouddevice.status -eq "Up")
                {
                    $url = "http://localhost:5000/img/up.png"
                }

                if($clouddevice.status -eq "Down")
                {
                    $url = "http://localhost:5000/img/down.png"
                }

                if($clouddevice.status -eq "Warning")
                {
                    $url = 'http://localhost:5000/img/warning.png'
                }

                if($clouddevice.status -eq "Paused (paused)")
                {
                    $url = "http://localhost:5000/img/pause.png"
                }

                if($clouddevice.status -eq "Unusual")
                {
                    $url = "http://localhost:5000/img/unusual.png"
                }

                foreach ($col in $clouddt.Columns) {
                    switch ($clouddevice.sensor)
                    {
                        "$($col.ColumnName)"
                        {
                            $clouddr["$($col.ColumnName)"] = $url
                            break
                        }
                    }
                }
            }
            $clouddt.Rows.Add($clouddr)
        }
    }
    for ($i = 0; $i -lt $clouddt.Rows.Count; $i++)
    {
        foreach ($emptycell in $clouddt.Columns) {
            $cellname = $emptycell.ColumnName
            if ($clouddt.Rows[$i].$cellname.ToString() -eq "")
            {
                $clouddt.Rows[$i].Ping = "http://localhost:5000/img/na.png"
            }
        }
    }

    $CloudDataGrid = $clouddt | Select-Object *

    New-UDPaper -Elevation 0 -Content {
        New-UDTypography -Text "Last Refresh: $((Get-Date).DateTime)" -Variant body1
    }

    New-UDPaper -Elevation 1 -Content {
        $CloudGridColumns = @(
            foreach ($colname in $clouddt.Columns) {
                $colname = $colname.ColumnName
                if ($colname -eq "Device") {
                    New-UDTableColumn -Property $colname
                } else {
                    
                    New-UDTableColumn -Property $colname -Render {
                        New-UDImage -Url $EventData.$colname
                    }
                }
            }
        )
        
        New-UDTable -Id 'sslgrid' -Data $CloudDataGrid -Columns $CloudGridColumns -Title 'Services' -ShowSearch -ShowPagination -PageSizeOption @(5,10,20)
    
    }

thank i will take a look at this later tonight.

Kool beans!!

Thank you so much!

Hey @AlonGvili , any goods news regarding this ?

Thanks

I send you a private message 3d ago

1 Like