# Unable to get the Output of Hashtable in Table format

**URL:** <https://forums.powershell.org/t/unable-to-get-the-output-of-hashtable-in-table-format/21194>\
**Category:** PowerShell Help\
**Created:** [December 19, 2022, 8:00pm UTC](https://forums.powershell.org/t/unable-to-get-the-output-of-hashtable-in-table-format/21194 "2022-12-19T20:00:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anudeepmails](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anudeepmails](https://forums.powershell.org/u/anudeepmails)\
**Post date:** [December 19, 2022, 8:00pm UTC](https://forums.powershell.org/t/unable-to-get-the-output-of-hashtable-in-table-format/21194/1 "2022-12-19T20:00:47Z")

</div>

output of below script is showing in hashtable format.

```auto
param(
    [string[]]$computername
)
foreach($computer in $computername){
$filebeat_status_before = get-service -name filebeat -computername $computer
get-service -name filebeat -computername $computer |Restart-Service
$filebeat_status_after = get-service -name filebeat -computername $computer

$props = [ordered]@{'computername'=$computer;'status_before'=$filebeat_status_before.Status;'status_after'=$filebeat_status_after.status
            }
$obj = New-Object -TypeName PSobject -Property $props

write-output "$obj"
}

```

Output is showing as below  
@{computername=XYZ; status\_before=Running; status\_after=Running}

but it should show as below:  
computername = XYZ  
status\_before = Stopped  
status\_after = Running

Any thoughts how to fix this output format.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 19, 2022, 8:56pm UTC](https://forums.powershell.org/t/unable-to-get-the-output-of-hashtable-in-table-format/21194/2 "2022-12-19T20:56:08Z")

</div>

Anudeep,  
Welcome to the forum. 👋🏽

I’d use a `[PSCustomObject]` instead of a hashtable in such a case. It’s even easier to read and maintain.

```auto
param(
    [string[]]$computername
)
foreach ($computer in $computername) {
    $filebeat_status_before = Get-Service -Name filebeat -ComputerName $computer
    Get-Service -Name filebeat -ComputerName $computer | Restart-Service
    $filebeat_status_after = Get-Service -Name filebeat -ComputerName $computer

    [PSCustomObject]@{
        ComputerName = $computer
        Status_Before = $filebeat_status_before.Status
        Status_After = $filebeat_status_after.Status
    }
}

```

---

<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/unable-to-get-the-output-of-hashtable-in-table-format/21194/3 "2024-05-16T20:16:09Z")

</div>

Closed on May 16, 2024, 8:16pm UTC


