【问题标题】:start a PowerShell script as local system user and redirect the script output以本地系统用户身份启动 PowerShell 脚本并重定向脚本输出
【发布时间】:2017-09-13 12:07:45
【问题描述】:

我需要以用户“nt authority\system”的身份启动一个 PowerShell 脚本,并希望将脚本的输出重定向到一个文件。要以系统用户身份启动 PowerShell,我使用 PsExec.exe
我的代码确实有效:

$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 参数应该是最后一个参数,但我认为输出/流的重定向也是如此。

【问题讨论】:

  • 重定向是 shell 的一个特性,而不是 PsExec 的特性。

标签: powershell


【解决方案1】:

这行得通。你可以这样做吗?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 2015-06-30
    • 1970-01-01
    相关资源
    最近更新 更多