I have a powershell hashtable which is generated from looking at services and their status,
the code to get generate the values is as follows:
$table = @{}
foreach ($service in $services)
{
$obj = Get-Service -name $service -ErrorAction SilentlyContinue
if ($obj -ne $null){
$table[$service] = $obj.status
}
}
'attempt 1 at outputting the table, shows the inline response
$table | out-string | write-host
'attempt 2 at outputting the table, gives no output
$table
'attempt 3 at outputting the table, shows no output
write-output $table
I am trying to write the values to the screen as follows (just by calling the hastable or using write-output, the results are identical,
This works fine in a test example but not within my script:
PS C:\WINDOWS\system32> $table
Name Value
---- -----
Service1 Running
Service2 Running
Within my script I get this:
Name Value
---- -----
{Service1, Service2 ... {Stopped, Stopped, Stopped}
I have attempted to force the output using format-table, and various combinations of write-output / write-host
Can someone please give me a pointer?
why you decided for a hashtable? don't see any reason in this code.
BTW formatting functions are formatting to the given output - you were using screen formatting and trying to push it to the file. that is wrong. use export functions. you can of course try simple out-file but in general objects are complex creatures with some hierarchy. screen is only for your eyes - stop thinking in what you see but what is really is.