Redirecting Start-Service output from a remote session

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
JaimeBou
Posts: 27
Last visit: Wed Jan 31, 2024 8:52 am
Has voted: 1 time

Redirecting Start-Service output from a remote session

Post by JaimeBou »

I have a routine that starts a service on a remote server:

Invoke-command -Session $ession -ScriptBlock { Start-Service -InputObject $args[0] } -ArgumentList $svc.Name

The routine works fine.

I wanted to explore redirecting the messages that I see in the OUTPUT tab/console to a text box to give the user additional feedback.

This is an example of what I see:

WARNING: Waiting for service 'DataCaptor Interface Server (DataCaptor Interface Server)' to start...

I have tried assigning the Invoke-command to a variable but that did not seem to help.

Can someone point me in the right direction?

Thank you in advance.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Redirecting Start-Service output from a remote session

Post by jvierra »

No need to use Invoke-Command to start a remote service:

Get-Service $svc.Name -ComputerName <comouter> | Start-Service

To learn about redirecting review the following:

help redirection
User avatar
JaimeBou
Posts: 27
Last visit: Wed Jan 31, 2024 8:52 am
Has voted: 1 time

Re: Redirecting Start-Service output from a remote session

Post by JaimeBou »

Thank you
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked