Use a variable as an image name

I have a script that puts an image in a UDcard. The problem is the image is always different so I can’t use a static path. The image name will come from a csv file so with a few conditions in the “Import-csv” command, the script will know what the name (which is a number) of the file is. The problem I’m having is I can’t seem to use a variable to represent the image in the image file path. Here’s the script:


$csvData = Import-Csv -Path 'C:\dashboard\dashboard.csv'

$navigation = @(
    New-UDListItem -Label "Tamper"  
)

$pages = @()
$pages += New-UDPage -Name 'Live Analytics' -Content {
    Foreach ($item in $csvData) {
       New-UDDynamic -Content {
        New-UDLayout -Columns 4 -Content {
            New-UDCard -Title $item.area -Content {
                New-UDTypography -Text "Detector: $($item.detector)"
                New-UDTypography -Text "ID: $($item.ID)"
                New-UDTypography -Text "Date: $($item.date)"
                New-UDTypography -Text "Time: $($item.time)"

               $imageName = $item.ID

            } -Image /images/$imageName.png
        }
    } -AutoRefresh -AutoRefreshInterval 5 
}

} -NavigationLayout permanent -Navigation $navigation

New-UDDashboard -Title "Hello, World!" -Pages $pages
 


“} -Image /images/$imageName.png” doesn’t work. Appreciate any help with this. Thanks

It looks like you are defining image name within the script block. What happens when you do this?

$imageName = $item.ID
New-UDCard -Title $item.area -Content {
    New-UDTypography -Text "Detector: $($item.detector)"
    New-UDTypography -Text "ID: $($item.ID)"
    New-UDTypography -Text "Date: $($item.date)"
    New-UDTypography -Text "Time: $($item.time)"
} -Image /images/$imageName.png

Ah i see. Yeah, that did it. Thank you!