如何转换PowerShell脚本以在.bat中使用

时间:2017-10-23 19:48:28

标签: powershell batch-file cmd

我试图让这个PowerShell命令脚本在批处理文件中运行,但似乎无法让它工作。先感谢您。它在PowerShell中运行良好,我只需要它就可以在bat中工作。

$wshell = New-Object -ComObject WScript.Shell;
$wshell.AppActivate('APPNAME')
Sleep 1
$wshell.SendKeys('{ENTER}');

1 个答案:

答案 0 :(得分:0)

尽可能以最短的方式解决发生的事情,如徽标,个人资料和政策受阻:

powershell -ExecutionPolicy Bypass -NoProfile -NoLogo -Command "$wsh=New-Object -ComObject wscript.shell;$wsh.AppActivate('Appname');Start-Sleep 1000;$wsh.SendKeys('{ENTER}')"

另外,在PowerShell脚本中不需要分号,除非在同一行上分隔语句。