You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PsExec执行PowerShell脚本报错%1 is not a valid Win32 application求助

问题根源与解决方案:PsExec执行PowerShell脚本报错%1 is not a valid Win32 application

嘿,这个问题我之前也碰到过!错误%1 is not a valid Win32 application的根源其实很直白——PsExec默认只能直接启动Win32可执行文件(比如.exe、.bat这类原生可执行程序),而你的test.ps1是PowerShell脚本,它本身并不是可执行文件,Windows系统不知道该用什么程序去解析运行它,所以才会抛出这个错误。

要解决这个问题,你需要明确告诉PsExec:先启动PowerShell解释器,再让它去加载执行你的脚本。这里有几种靠谱的写法:

方法1:基础执行方式

在C:\pstools目录下执行这条命令即可:

psexec.exe powershell.exe -File C:\test\test.ps1

如果你的脚本需要管理员权限才能获取完整的服务信息(毕竟有些服务需要高权限查看),可以加上-h参数(让PsExec以高权限启动PowerShell):

psexec.exe -h powershell.exe -File C:\test\test.ps1

方法2:后台静默执行

如果你不想弹出PowerShell窗口,想让脚本在后台运行,可以加上-WindowStyle Hidden参数:

psexec.exe powershell.exe -WindowStyle Hidden -File C:\test\test.ps1

额外小提示

  • 要是你的系统环境变量里没包含PowerShell的路径,记得写全路径,比如C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • 如果遇到PowerShell执行策略阻止脚本运行的情况,可以加上-ExecutionPolicy Bypass参数临时绕过限制:
psexec.exe powershell.exe -ExecutionPolicy Bypass -File C:\test\test.ps1

内容的提问来源于stack exchange,提问作者Daniel Ben Eliyahu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:32:43