0

I wish to create a table from my Powershell Output. The output is correct if I only use 4 columns

Naam         RFC    Status                Last_Modification_Date
----         ---    ------                ----------------------
Daan 838065 Approved to Implement 2017-12-19T10:21:56   
Daan 838061 Approved to Implement 2017-12-19T10:48:29   
Daan 837103 Approved to Implement 2017-12-19T07:08:33   
Daan 835761 Approved to Implement 2017-12-15T08:34:44   
Daan 835762 Approved to Implement 2017-12-18T08:38:51   
Daan 835748 Approved to Implement 2017-12-15T12:25:46   
Daan 834721 Approved to Implement 2017-12-08T11:48:13   
Daan 834656 Approved to Implement 2017-12-08T11:48:30   
Daan 831541 Approved to Implement 2017-12-07T10:16:21  

But as soon as I add a column more, I get this kind of output, how do I get the output to be as I prefer?

Naam                   : Theunis Daan
RFC                    : 837103
Status                 : Approved to Implement
Last_Modification_Date : 2017-12-19T07:08:33
Start                  : 1513317360

Naam                   : Theunis Daan
RFC                    : 835761
Status                 : Approved to Implement
Last_Modification_Date : 2017-12-15T08:34:44
Start                  : 1513238880

Naam                   : Theunis Daan
RFC                    : 835762
Status                 : Approved to Implement
Last_Modification_Date : 2017-12-18T08:38:51
Start                  : 1513253340

The code that gives the correct output is uncommented, the full output I'd wish is in comment, but that gives me the wrong output style.

foreach ($change in $Changes.objects) {
        if ($change.assignee_full_name -eq "Daan"){
            $Output = "" | select "Naam", "RFC", "Status", "Last_Modification_Date"
            $Output.Naam = $change.assignee_full_name
            $Output.RFC = $change.change_ref
            $Output.Status = $change.change_status
            $Output.Last_Modification_Date = $change.last_mod_date
            Write-Output $Output 

            <#$temp = "" | select "RFC", "Summary", "Status", "Last_Modification_Date", "Start", "Need_By", "Assignee"
            $temp.RFC = $change.change_ref
            $temp.Summary = $change.change_summary
            $temp.Status = $change.change_status
            $temp.Last_Modification_Date = $change.last_mod_date
            $temp.Start = $change.planned_date_timestamp
            $temp.Need_By = $change.change_active_date_timestampe
            $temp.Assignee = $change.assignee_full_name
            Write-Output $temp #>
        }
    }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    Write-output is for writing output. It's not the same as format-table. – Reza Aghaei Dec 19 '17 at 14:20
  • Same problem, just reversed. – Ansgar Wiechers Dec 19 '17 at 14:26
  • The "Workaround" there doesn't really solve it though, the output is even worse even. – Daan Theunis Dec 19 '17 at 14:39
  • I guess that the title of your question is confusing. If you want to add a column (like `.Need_By`), you will need to use [`Add-Member -NoteProperty`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/add-member?view=powershell-5.1) or align the rest of the objects (or at least the first one), see: https://stackoverflow.com/a/44429084/1701026. Try this: `foreach ($change in $Changes.objects) {...} | Union` – iRon Dec 19 '17 at 15:42
  • `Format-Table [-AutoSize]` doesn't work for you? If so, please provide more information about the desired and actual output. Representative(!) samples usually help. – Ansgar Wiechers Dec 19 '17 at 17:25

0 Answers0