以本地系统用户身份启动PowerShell脚本并重定向脚本输出
我需要以用户“nt authority\system”的身份启动PowerShell脚本,并希望将脚本的输出重定向到文件。要以系统用户身份启动PowerShell,我使用以本地系统用户身份启动PowerShell脚本并重定向脚本输出,powershell,Powershell,我需要以用户“nt authority\system”的身份启动PowerShell脚本,并希望将脚本的输出重定向到文件。要以系统用户身份启动PowerShell,我使用 我的代码非常糟糕,但它确实有效: $Arguments = "-i -s Powershell.exe -File C:\temp\SetupNlb.ps1" Start-Process "C:\temp\PsExec.exe" -Wait -ArgumentList $Arguments 现在,输出重定向不起作用的代码:
我的代码非常糟糕,但它确实有效:
$Arguments = "-i -s Powershell.exe -File C:\temp\SetupNlb.ps1"
Start-Process "C:\temp\PsExec.exe" -Wait -ArgumentList $Arguments
现在,输出重定向不起作用的代码:
$Arguments = "-i -s Powershell.exe -File C:\temp\SetupNlb.ps1 *> C:\temp\SetupNlb.log"
Start-Process "C:\temp\PsExec.exe" -Wait -ArgumentList $Arguments
问题可能是Powershell.exe的-File参数应该是最后一个参数,但我认为输出/流的重定向也是如此。这是可行的。你能改做这个吗
C:\temp\PsExec.exe -i -s powershell.exe -Command "c:\temp\SetupN1b.ps1 *> c:\temp\SetupN1b.log"
重定向是shell的一项功能,而不是PsExec的一项功能。