【问题标题】:psexec powershell outputpsexec powershell 输出
【发布时间】:2012-10-24 10:46:45
【问题描述】:

我尝试像这样远程执行 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

当一个运行命令远程执行这个脚本时,脚本定位在远程机器上,在本地机器上什么也不输出。在 cmd.exe 中运行的命令。如何将输出输出到本地控制台?

【问题讨论】:

  • 远程主机上是否存在C:\tst\tst.ps1?是否允许执行脚本 (Get-ExecutionPolicy)?
  • 是的,脚本存在“脚本定位在远程机器上”允许执行。PsExec v.1.98。
  • 你试过psexec ... powershell -NoLogo -File C:\tst\tst.ps1吗?
  • 它对我有什么帮助?它关闭了 powershell 上的启动徽标,但不能帮助我在输出时获得返回值
  • PSRemoting 怎么样? New-PSSession之类的?您可以在远程系统上记录脚本并将其复制回源计算机。

标签: powershell psexec output


【解决方案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

但我不知道如何传递 args 字符串以使用参数执行远程脚本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多