convert string array to string in hashtable to export to CSV

Welcome Forums General PowerShell Q&A convert string array to string in hashtable to export to CSV

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

 
Moderator
3 weeks, 5 days ago.

  • Author
    Posts
  • #146460

    Participant
    Points: 42
    Rank: Member

    i have the following code , is output the RSOP XML value to CSV:

    $a=@{
    'name' =$xmldoc.rsop.ComputerResults.ExtensionData.Extension.SecurityOptions.Display |
    Where {$_.Name -eq "Interactive logon: Message text for users attempting to log on" }|  Select -expand  "DisplayStrings"  | Select -expand Value
    
    }
    
    $a |export-CSV b.csv

    as expected, the output not what i wanted,it output systemobject[] .

    I tried to join the string, but failed

    ......
    'Name'=$xmldoc.rsop.ComputerResults.ExtensionData.Extension.SecurityOptions.Display |
    Where {$_.Name -eq "Interactive logon: Message text for users attempting to log on" }|  Select -expand  "DisplayStrings"  | Select -expand Value, @{Name='DisplayStrings';Expression={[string]::join(“;”, ($_.DisplayStrings))}}  
    
    ..........

    I cant use psobject method due to my production environment security rules, Any help will be appreciated.

  • #146462

    Participant
    Points: 411
    Helping Hand
    Rank: Contributor

    See the properties of the return object, that will help you to retrieve the required values.

    $a | Get-Member

    As far as my understanding $a.name needs to be exported...

    $a.name | Export-Csv b.csv
  • #146532

    Moderator
    Points: 1,981
    Helping Hand
    Rank: Community Hero

    ... | Select -expand Value

    It depends on what is in Value property. If its an object, then string conversion(which happens internally) displays it to system.object.

    Try an out-String at the end.

    ... | Select -expand Value | Out-String

You must be logged in to reply to this topic.

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