PsExec的记录输出从powershell开始

时间:2014-11-18 10:05:23

标签: powershell logging psexec

我从powershell启动PsExec,效果很好。太棒了但我无法记录任何东西。它创建一个空的文件。

$InstallerFolder = "\\dc01\e"
$Domain = "domain"
$DomainUser = "admin"
$Password = "password"



$nodes = Get-Content "$InstallerFolder\Side-Scripts\nodes.txt"

foreach ($node in $nodes) {
$Arguments = @()
$Arguments += "\\$node"
$Arguments += "-u"
$Arguments += "$Domain\$DomainUser"
$Arguments += "-p"
$Arguments += "$Password"
$Arguments += "-h"
$Arguments += "`"$InstallerFolder\Side-Scripts\start.bat`""
$Arguments += ">>`"$InstallerFolder\logs\$node.txt`""
$Arguments += "-n"
$Arguments += "120"

Start-Process -Filepath "$InstallerFolder\Side-Scripts\PsExec.exe" $Arguments -NoNewWindow


}
exit;

我也试过了     1 GT;     2 - ;     > 相同的结果。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以尝试将重定向发送到变量,然后将该输出发送到文件,而不是将重定向放在psexec行中。

$InstallerFolder = "\\dc01\e"
$Domain = "domain"
$DomainUser = "admin"
$Password = "password"

$psexec = "$InstallerFolder\Side-Scripts\PsExec.exe"

$nodes = Get-Content "$InstallerFolder\Side-Scripts\nodes.txt"

foreach ($node in $nodes) {
    $commandOutput = ((&$psexec \\$node `"$InstallerFolder\Side-Scripts\start.bat`" -u $Domain\$DomainUser -p $Password -h -n 120) | Out-String)
    $commandOutput | out-file "$InstallerFolder\logs\$node.txt"
}