For each array results displaying on seperate lines

Welcome Forums General PowerShell Q&A For each array results displaying on seperate lines

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

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #170230

    Participant
    Topics: 1
    Replies: 1
    Points: 15
    Rank: Member

    Hi There

    Newbie here, trying to get my results to appear in two columns on one line....

    $results = $files | ForEach-Object { $_ ; $_ | Get-Content | Measure-Object -Line}

    $results | Format-Table Name,Lines

    Name Lines

    —- —–

    (A01) SerialAmendments.csv

    9

    (A02) New Meters.csv

    89

    (A03) Disconnected Meters Pelican.csv

    4

    any help appreciated 🙂

  • #170239

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero

    Well,

    What you need here is just a Select-Object cmdlet. You can use calculated properties to do the measure. I would like you to have a try before adding some code. Below link will help you to do that.

    PowerShell Tips for System Administrators: Calculated Properties

    PS: Format-Object cmdlet is supposed to be used only when intent is just to display the output in console as it completely destroys the objects by formatting it to text which becomes non usable when consumed by other cmdlet.

    finally, please use below instructions to post the code with code formatting options.
    https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/

  • #170308

    Participant
    Topics: 1
    Replies: 1
    Points: 15
    Rank: Member

    Thanks! This is what I ended up with, thanks for the link it was very helpful. 🙂

    $results = $files | Select-Object -Property `
    @{ N = 'name' ; E = { $_.Name}},
    @{ N = 'modification_date' ; E = { $_.LastWriteTime} },
    @{ N = 'row_count'; E = { ($_ | Get-Content | Measure-Object -Line).Lines } }
    
  • #170329

    Participant
    Topics: 1
    Replies: 1530
    Points: 2,591
    Helping Hand
    Rank: Community Hero

    Why do you rename the property "Name" to "name"?

You must be logged in to reply to this topic.