Hash Table

Heres my hash Table


$h = [ordered]@{
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}



$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

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.

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

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                                                                           

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

actually your example is perfect thank you