简体   繁体   English

psexec powershell输出

[英]psexec powershell output

I try remote execute powershell script like this: 我尝试像这样远程执行powershell脚本:

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

Source code for 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

When a run command to remote execute this script, script locate on remote machine, in local machine in output nothing. 当运行命令远程执行此脚本时,该脚本位于远程计算机上,而在本地计算机中则无输出。 Command running in cmd.exe. 在cmd.exe中运行的命令。 How i can get output to local console? 我如何将输出输出到本地控制台?

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

This construction help you to run remote powershell script, but script should be locate on remote computer. 此构造可帮助您运行远程Powershell脚本,但是脚本应位于远程计算机上。

and second construction 和第二建设

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

but i don't know how i can pass args string for execute remote script with param 但我不知道如何传递args字符串以使用param执行远程脚本

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

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