在批处理脚本条件下的PowerShell命令

在批处理脚本条件下的PowerShell命令,第1张

概述在批处理脚本条件下的PowerShell命令

我需要一些脚本来做这样的事情:

if (results from PowerShell command not empty) do something

PowerShell命令基本上是

powershell -command "GetInstalledFoo"

无法运行一个Java应用程序作为windows服务

如何检查文件扩展名,并相应地打开windowsbatch file中的默认程序

batch file在windows中运行其他batch file

如何改变目录到你的homedrive?(C:,D:等..)

下载VBS错误“(空):0x80072EE6”

我试过if (powershell -command "GetInstalledFoo" != "") echo "yes"但得到错误 – -command was unexpected at this time. 这有可能完成吗? 该命令最终将作为cmd /k的命令运行。

在shift之后使用`%*`

创build交互式窗口.bat文件,将开发文件复制到生产文件夹中

我们可以从共享path运行batch file(.bat)吗?

从.bat文件执行PowerShell脚本时出错

Base64编码“string” – 命令行windows?

只要至少有一行输出不以FOR / Fol字符开始(默认为; ),并且不完全由分隔字符组成(默认为空格和制表符),bartekB的答案将起作用。 通过适当的FOR / F选项,可以使其始终工作。

但是,这是一个简单的(我相信更快)的方式来处理应始终工作的多行输出。

for /f %%A in ('powershell -noprofile -command gwmi win32_process ^| find /v /c ""') do if %%A gtr 0 echo yes

另一种选择是使用临时文件。

powershell -noprofile -command gwmi win32_process >temp.txt for %%F in (temp.txt) if %%~zF gtr 0 echo yes del temp.txt

第三种方法:从PowerShell脚本中设置一个环境变量并在批处理文件中测试它?

我想如果不是最好的解决方案。 我会用for /f来代替:

for /f %r in ('powershell -noprofile -command echo foo') do @echo bar

这应该给你“吧”,而这个:

for /f %r in ('powershell -noprofile -command $null') do @echo bar

… 不应该。 在实际的.bat / .cmd文件中,您必须将%(%% R)

或者更好,如果你不想很多酒吧的返回…:

(for /f %r in ('powershell -noprofile -command gwmi win32_process') do @echo bar) | find "bar" > nul && echo worked

总结

以上是内存溢出为你收集整理的在批处理脚本条件下的PowerShell命令全部内容,希望文章能够帮你解决在批处理脚本条件下的PowerShell命令所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1270438.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存