Reputation: 31
I am trying to change the color of my get-service output. It does not seem to allow me to use the write-host -forgroundcolor parameter after get-service. Is there any way around this?
I have tried the following configurations:
get-service write-host -foregroundcolor "green"
get-service -foregroundcolor "green"
I can get it to kind of work if I save get-service into a variable and place write-host in front like so:
$var = get-service
write-host $var -foregroundcolor "green"
The problem with this is the output is not formatted correct and becomes a single line.
Upvotes: 2
Views: 866
Reputation: 71
Or you can:
Write-Host -ForegroundColor Green (Get-Service | out-string)
Upvotes: 0
Reputation: 19684
Get-Service | Out-String [-Stream] | Write-Host -ForegroundColor Green
According to Out-String
's help topic:
The Out-String cmdlet converts the objects that Windows PowerShell manages into an
array of strings. By default, Out-String accumulates the strings and returns them as
a single string, but you can use the stream parameter to direct Out-String to return
one string at a time. This cmdlet lets you search and manipulate string output as
you would in traditional shells when object manipulation is less convenient.
By using the -Stream
argument, you don't wait for Get-Service
to complete execution but it takes inputs as it gets them.
Upvotes: 1