【问题标题】:How to execute this powershell commands in a batch file?如何在批处理文件中执行此 powershell 命令?
【发布时间】:2016-05-10 19:25:15
【问题描述】:

我正在尝试运行这个 powershell 命令:

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize > C:\Users\Administrateur\Desktop\Mysoftware.txt

在批处理文件中。这就是我现在得到的:

powershell.exe -noexit -command "& {Get-ItemProperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'; Select-Object DisplayName, DisplayVersion, Publisher, InstallDate; Format-Table -Autosize; > 'C:\Users\Administrateur\Desktop\Mysoftware.txt';}"

但它告诉我 ">" 不是命令

我要做的是在 MySoftware.txt 文件中获取计算机所有软件的列表。

感谢您的帮助

【问题讨论】:

  • 反引号?写输出?顺便说一句,为什么批处理而不是豪华脚本?
  • 您添加了 ;在您显示的豪华命令中没有的 > 之前。
  • 另外,这只会显示已安装的 32 位应用程序。

标签: powershell batch-file command-line


【解决方案1】:

去掉“;”在通过“>”重定向到文件并使用“|”之前将命令的输出传递给下一个命令的输入,而不是放置“;”在每个命令的末尾。

powershell.exe -noexit -command "& {Get-ItemProperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -Autosize > 'C:\Users\Administrateur\Desktop\Mysoftware.txt' }"

【讨论】:

    【解决方案2】:

    你可以试试这条线吗?

    powershell.exe -noexit -command "& {Get-ItemProperty 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | export-csv 'C:\Users\Administrateur\Desktop\Mysoftware.csv' -nti}"
    

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 2020-08-13
      • 2020-09-10
      • 1970-01-01
      相关资源
      最近更新 更多