# Hash Table 

**URL:** <https://forums.powershell.org/t/hash-table/2874>\
**Category:** PowerShell Help\
**Created:** [July 23, 2014, 5:43am UTC](https://forums.powershell.org/t/hash-table/2874 "2014-07-23T05:43:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [July 23, 2014, 5:43am UTC](https://forums.powershell.org/t/hash-table/2874/1 "2014-07-23T05:43:52Z")

</div>

Heres my hash Table

```
$h = [ordered]@{
Computername=$env:computername
ServiceState = "wscsvc", "CcmExec" | foreach {Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" | select Name, State }
ServiceStartUp = "wscsvc", "CcmExec" | foreach {Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" | select Name, StartMode}

}

[pscustomobject]$h

$h | select -expandproperty values

# I get this

Name Value                                                                        
---- -----                                                                        
Computername BR-ADMIN3                                                                    
ServiceState {@{Name=wscsvc; State=Running}, @{Name=CcmExec; State=Running}}              
ServiceStartUp {@{Name=wscsvc; StartMode=Auto}, @{Name=CcmExec; StartMode=Auto}}
```

how do i remove the {@{

thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [July 23, 2014, 5:51am UTC](https://forums.powershell.org/t/hash-table/2874/2 "2014-07-23T05:51:15Z")

</div>

That’s how Powershell displays arrays and PSObjects as text. (Arrays go into a pair of curly braces with comma-separated values, and PSObjects are displayed like hashtable literals.) You can certainly change the text that’s displayed on screen if you like, but you’d have to decide what you want it to look like.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [July 23, 2014, 5:54am UTC](https://forums.powershell.org/t/hash-table/2874/3 "2014-07-23T05:54:44Z")

</div>

I’m not sure what you’re doing with that hashtable. Here’s a different approach which builds an array of objects, which are displayed in a more user-friendly way by Format-Table:

```
$services = "wscsvc", "CcmExec" | foreach {
    Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" |
    select @{Name = 'ComputerName'; Expression = { $env:computername }}, Name, State, StartMode
}

$services | Format-Table -AutoSize
```

---

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [July 23, 2014, 5:56am UTC](https://forums.powershell.org/t/hash-table/2874/4 "2014-07-23T05:56:58Z")

</div>

Hi Dave id like it to look like this if possible i would also like to export-csv to results

I am remoting into 70 machines and building a report basec on 2 criteria state and startup mode

```
Name State                                                                             
---- -----                                                                             
wscsvc Running                                                                           
CcmExec Running
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [July 23, 2014, 5:59am UTC](https://forums.powershell.org/t/hash-table/2874/5 "2014-07-23T05:59:28Z")

</div>

That’s easy enough, but you don’t have ComputerName or StartMode in that output, both of which were part of your original code. Should they be there as well? (If so, use the code from my previous post.)

```
$services = "wscsvc", "CcmExec" | foreach {
    Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" |
    select Name, State
}

$services | Format-Table -AutoSize
$services | Export-Csv -Path C:\Some\Csv\File.csv
```

---

<div class="post-metadata">

**Author:** ![imessage357\_h](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imessage357\_h](https://forums.powershell.org/u/imessage357_h)\
**Post date:** [July 23, 2014, 6:01am UTC](https://forums.powershell.org/t/hash-table/2874/6 "2014-07-23T06:01:09Z")

</div>

actually your example is perfect thank you

---

<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:47pm UTC](https://forums.powershell.org/t/hash-table/2874/7 "2024-05-16T20:47:46Z")

</div>


