Pull data from csv with PowerShell tile

Hello Peter,

It took a little time to figure this out, but it wasn’t anything related to page timeframe.

After some trial and error, it appears that the culprit is the -header parameter of the Import-CSV command.

More specifically, when the source data (in your case, a CSV) has column headings AND the -header parameter, a new row is created that contains the column headings.

Ironically, because the original code is being “strict” with its data types (a sign of a good programmer), the data is “missing.”

This is how it shows up in SquaredUp, you can see the empty row:

But if you change the code to not be strict (in the console, not SquaredUp), it shows up like this:

image

Another irony, if you remove the “strictness” in SquaredUp, the tile refuses to render because there is text in your value field!

But, with all of that being said, that blank row is not being properly handled by SquaredUp because instead of ignoring it, it renders a graph that is incorrect (or malformed?).

In any case, here is your original script, with the offending code removed:

#SquaredUp tile
$data = Import-Csv -LiteralPath C:\SquaredUp\report.csv -Delimiter ','
$data | Select-Object @{
    Name = "DateTime";
    Expression = {[datetime]::ParseExact($_.DateTime, 'dd-MM-yyyy HH:mm:ss', $null)}
    },
@{
    Name = "UploadTime";
    Expression = {[int]$_.Uploadtime}
},
@{
    Name = "DownloadTime";
    Expression = {[int]$_.Downloadtime}
}

I hope that help!

Cheers!
-Shawn

1 Like