Tables on the Portal for Scripts

Product: PowerShell Universal
Version: 5.0.15

I’m getting some inconsistent output when attempting to set the Portal Output Type to “Table”. It seems like if its a table of 1 object, it just completely refuses to display. It just says, “No Data.” The Job will say successful, and the log in the admin portal will display the table in CLI with zero issues.

I’ll just use this as an example:
Get-LocalUser
Displays a result in a table

Get-LocalUser | Where-Object { $_.name -like "Administrator"}
Displays Zero Results or table in the portal

Check to see if its the where-object:
Get-LocalUser | Where-Object { $_.name -like "*G*"}
Displays Table with 2 results correctly.

I already tried force wrapping it in an array with no luck:

$result = Get-LocalUser | Where-Object { $_.name -like "Administrator"}
if ($result.Count -eq 1) {
    $result = @($result)
}

It just seems to completely refuse to make a table if there is only one result?

Anyone else having this issue, or seen it before?

I don’t use the portal stuff.
But it seem you got trapped by an old powershell speciality.

When you create an array with just one item, and the refer to the variable,
it is not seen as array, but just as that item.

In order to see a “one item array” as such, you need to force it.

try in a local pwsh window:

$a=get-localuser
$a.gettype()

you will get type of System.Array.

$a=get-localuser | ?{ $_.name -like "Admnistrator" }
$a.gettype()

you will get type of Microsoft.PowerShell.Commands.LocalPrincipal

you can force array interpretation by:

[array]$a=get-localuser | ?{ $_.name -like "Administrator" }
$a.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

They way you force the array, is making sure an array gets assigned to a normal variable.
But this variable lateron gets interpreted as whatever…

By using a casting operator, chances are that your variable will be interpreted correctly.

Not sure if that helps for what you are trying to achieve

Yeah, I tested out your way as well, same result. The last example I posted does the same thing. It’s just checking to see if there was only one object first then wrapping it.

$result = Get-LocalUser | Where-Object { $_.name -like "Administrator"}
if ($result.Count -eq 1) {
    $result = @($result)
}

Force wrapping it into an array does not seem to fix this issue.

Probably an issue with the table rendering. I’ll open an issue.

1 Like

I think this is also happening with New-UDTabs if only one tab is available:


You can see the “Max” tab is selected, but has nothing in it. When we add a dummy tab for “Other”:

You can see the additional info.

Let me know if this is a separate issue and I can open one (: