# Can't align result into table. Two commands

**URL:** <https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012>\
**Category:** PowerShell Help\
**Created:** [November 25, 2022, 4:24pm UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012 "2022-11-25T16:24:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenshoohustle](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kenshoohustle](https://forums.powershell.org/u/kenshoohustle)\
**Post date:** [November 25, 2022, 4:24pm UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012/1 "2022-11-25T16:24:03Z")

</div>

Hi Everyone,

I would like to create a report to email the replication status. But I can’t align the results on the table, the 2nd command creates new columns.

The command both have PSComputerName, so I want to align them if they have the same PSComputerName. I’m still new to PS scripting and I wanna know if there’s a better way to do this like new custom object?

```auto
Invoke-Command -ComputerName ("Server1","Server2","Server3") -ScriptBlock { (Get-SRPartnership | select SourceComputerName, SourceRGName, DestinationComputerName, DestinationRGName)} | Sort-Object PSComputerName | Export-CSV -Path "C:\SRPReport.csv" -NoTypeInformation
Invoke-Command -ComputerName ("Server1","Server2","Server3") -ScriptBlock { (Get-SRGroup | select IsSuspended, ReplicationMode, ReplicationStatus)} | Sort-Object PSComputerName | Export-CSV -Path "C:\SRGReport.csv" -NoTypeInformation

```

Below is a snip of ps1 for emailing the results of the two generated csv.

```auto
$csv = Import-Csv $output | Select "SourceComputerName", "SourceRGName", "DestinationComputerName", "DestinationRGName", "IsSuspended", "ReplicationMode", "ReplicationStatus" | ConvertTo-Html -head $a -Body "<H2>Storage Replica Status of File Servers</H2>"

```

Thanks in Advance.

Regards,  
Kent

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [November 25, 2022, 9:51pm UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012/2 "2022-11-25T21:51:45Z")

</div>

Well you could predefined the script block and pass everything in one block and then sort all of the results.

My interpretation is you want results from both commands combined and grouped by hostname.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 26, 2022, 12:01am UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012/3 "2022-11-26T00:01:29Z")

</div>

If you want to combine two different objects, then that is exactly what you need to do, create a new custom object. You take the properties you desire from each object into your final combined object. You can simplify your code greatly.

```auto
$scriptblock = {
    $partnership = Get-SRPartnership
    $group = Get-SRGroup

    [PSCustomObject]@{
        SourceComputerName = $partnership.SourceComputerName
        SourceRGName = $partnership.SourceRGName
        DestinationComputerName = $partnership.DestinationComputerName
        DestinationRGName = $partnership.DestinationRGName
        IsSuspended = $group.IsSuspended
        ReplicationMode = $group.ReplicationMode
        ReplicationStatus = $group.ReplicationStatus
    }
}

$output = Invoke-Command -ComputerName "Server1","Server2","Server3" -ScriptBlock $scriptblock

$output | Sort-Object -Property PSComputerName |
    Export-Csv -Path "C:\CombinedReport.csv" -NoTypeInformation

```

---

<div class="post-metadata">

**Author:** ![kenshoohustle](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@kenshoohustle](https://forums.powershell.org/u/kenshoohustle)\
**Post date:** [November 27, 2022, 10:36pm UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012/4 "2022-11-27T22:36:04Z")

</div>

Hi kryzdoug,

Thank you so much. That works like a charm.  
Will take note of creating a custom object on my future scripts.

Thank you again.

Best Regards,  
Kent

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/cant-align-result-into-table-two-commands/21012/5 "2024-05-16T20:16:16Z")

</div>


