Redirecting Start-Service output from a remote session

Ask your Windows 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.
Locked
User avatar
JaimeBou
Posts: 12
Joined: Fri Feb 09, 2018 9:57 am

Redirecting Start-Service output from a remote session

Post by JaimeBou » Tue Feb 12, 2019 7:22 am

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.

User avatar
jvierra
Posts: 13798
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Redirecting Start-Service output from a remote session

Post by jvierra » Tue Feb 12, 2019 12:02 pm

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: 12
Joined: Fri Feb 09, 2018 9:57 am

Re: Redirecting Start-Service output from a remote session

Post by JaimeBou » Tue Feb 12, 2019 12:05 pm

Thank you

Locked