0

I need to start a PowerShell script as user "nt authority\system" and want to redirect the output of the script to a file. To start PowerShell as system user I use PsExec.exe
My code so fart that does work:

$Arguments = "-i -s Powershell.exe -File C:\temp\SetupNlb.ps1"
Start-Process "C:\temp\PsExec.exe" -Wait -ArgumentList $Arguments

Now the code with output redirection that doesn't work:

$Arguments = "-i -s Powershell.exe -File C:\temp\SetupNlb.ps1 *> C:\temp\SetupNlb.log"
Start-Process "C:\temp\PsExec.exe" -Wait -ArgumentList $Arguments

The problem could be that the -File parameter of Powershell.exe should be the last parameter but i think the redirection of the output/streams as well.

1
  • 1
    Redirection is a feature of the shell, not of PsExec. Commented Sep 13, 2017 at 12:18

1 Answer 1

1

This works. Can you do this instead?

C:\temp\PsExec.exe -i -s powershell.exe -Command "c:\temp\SetupN1b.ps1 *> c:\temp\SetupN1b.log"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.