multiline property in psobject

Welcome Forums General PowerShell Q&A multiline property in psobject

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 10 months ago.

  • Author
  • #38042

    Points: 12
    Rank: Member

    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?

  • #38043

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #38056

    Points: 12
    Rank: Member

    Worked like a charm. Many thanks

The topic ‘multiline property in psobject’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort