multiline property in psobject

I’m trying to get the output of mu script in form of an html file. The output consists of selected properties of a custom psobject. One of them is a list of local admins which comes from the following
$admins = Invoke-Command -ComputerName $name -ScriptBlock {net localgroup “Administrators” | where{$_ -and $_ -notmatch “The command completed”} | select -skip 4}

where $admins is one of the properties named Local_administartors. When converted to html however I see System.Object instead of my list of admins in the corresponding cell.
What needs done with my $admins variable to have a nice list in the single cell?

So, the problem is that you’ve got an array, and PowerShell doesn’t know what you want done with it. I’m not sure how you’re producing the HTML, but ConvertTo-HTML, as one example, can’t “expand” an array for you. You’d need to do that yourself. I suspect that what you’ve got is an array of strings, which means you might try:

$admins = Invoke-Command -ComputerName $name -ScriptBlock {net localgroup “Administrators” | where{$_ -and $_ -notmatch “The command completed”} | select -skip 4} | Out-String

To turn the array into a flat string. Now, a potential problem is that it’ll probably use carriage returns, which HTML won’t render. I’m not sure if…

$admins -replace “\n\r”,“

Would work or not, but I’d try that, to convert the carriage return into HTML “line break” tags. I’d probably have to fuss with it along those lines until I got something like what I wanted.

Worked like a charm. Many thanks