Page 1 of 1

Redirecting Start-Service output from a remote session

Posted: Tue Feb 12, 2019 7:22 am
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.

Re: Redirecting Start-Service output from a remote session

Posted: Tue Feb 12, 2019 12:02 pm
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

Re: Redirecting Start-Service output from a remote session

Posted: Tue Feb 12, 2019 12:05 pm
by JaimeBou
Thank you