awineb
awineb

Reputation: 453

start a PowerShell script as local system user and redirect the script output

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.

Upvotes: 0

Views: 4249

Answers (1)

Brandon Stiff
Brandon Stiff

Reputation: 161

This works. Can you do this instead?

C:\temp\PsExec.exe -i -s powershell.exe -Command "c:\temp\SetupN1b.ps1 *> c:\temp\SetupN1b.log"

Upvotes: 1

Related Questions