我尝试像这样远程执行powershell脚本:
psexec -i \\host -u user -p pass PowerShell C:\tst\tst.ps1Tst.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中运行。如何将输出输出到本地控制台?
发布于 2012-10-29 15:53:08
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字符串
https://stackoverflow.com/questions/13047652
复制相似问题