psexec powershell输出

时间:2012-10-24 10:46:45

标签: powershell psexec output

我尝试远程执行powershell脚本,如下所示:

psexec -i \\host -u user -p pass PowerShell C:\tst\tst.ps1

tst.ps1的源代码:

$TempLogFilePath = "$(Get-Date -u "%Y-%m-%d")-LogFileEventLog.log"
Start-Transcript -Path "$TempLogFilePath" -Append
echo (Get-Date –f o)

Stop-Transcript
Exit 0

当一个run命令远程执行这个脚本时,脚本定位在远程机器上,在本地机器中输出什么都没有。命令在cmd.exe中运行。我如何获得输出到本地控制台?

1 个答案:

答案 0 :(得分:1)

PsExec.exe \\host -u domain\user -p pass cmd /c "echo . | %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe C:\WINDOWS\system32\Hello.ps1"

此构造可帮助您运行远程PowerShell脚本,但脚本应位于远程计算机上。

和第二次施工

Param(
[alias("sp")]
[string]$script_path,
[alias("u")]
[string]$user_name,
[alias("p")]
[string]$password,
[alias("h")]
[string]$host_name
)
$pass = convertto-securestring $password -asplaintext -force
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user_name,$pass
invoke-command -credential $mycred -computername $host_name -filepath $script_path

但我不知道如何通过param

传递执行远程脚本的args字符串