简体   繁体   English

从Powershell开始记录PsExec的输出

[英]Logging output from PsExec started from powershell

I'm starting PsExec from powershell which works fine. 我正在从Powershell启动PsExec,效果很好。 All great. 一切都很好。 But i can't get it to log anything. 但是我无法记录任何内容。 It creates a file which is empty. 它创建一个空文件。

$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;

I have also tried with 1> 2> > Same results. 我也尝试过1> 2>>相同的结果。

Thanks in advance. 提前致谢。

Instead of placing the redirect in the psexec line you can try sending it's output to a variable and then sending that output to a file like in the following. 您可以尝试将重定向的输出发送到变量,然后将该输出发送到文件,而不是将重定向放置在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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM