【问题标题】:Removing multiple apps using powershell?使用PowerShell删除多个应用程序?
【发布时间】:2011-12-18 17:14:11
【问题描述】:

我想创建一个脚本来删除一堆应用程序。启动脚本后,我想在没有用户交互的情况下执行此操作。

这是我目前的脚本;它不起作用,但希望你能看到我正在尝试做的事情:

$App = Get-Content "C:\ListOFApps.txt" #get a list of apps
$args= '/quiet /norestart' # stores arguments for start-process 

#gwmi gets the list of applications 
# where selects just the apps im interested in removing 
# start-process removes each app using msiexec with quiet and norestart options 

gwmi win32_product | where { $App -contains $_.Name } | foreach {Start-Process 'msicexec /uninstall ' $_.IdentifyingNumber -ArgumentList $args -wait}'

这是发生的错误:

ForEach-Object : Cannot process command because of one or more missing mandatory parameters: Process.
At C:\Users\username\AppData\Local\Temp\406f96a1-19b4-4e0d-af1b-b1ac2e32a6ba.ps1:3 char:62
+ gwmi win32_product| where { $App -contains $_.Name }| foreach <<<<  
+ CategoryInfo          : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.Commands.ForEachObjectCommand
 $_.IdentifyingNumber
Start-Process 'msicexec /uninstall $_.IdentifyingNumber' -ArgumentList $args -wait 

【问题讨论】:

  • “它不起作用”是什么意思?错误信息?意外行为?
  • 你之前不是发过同样的问题吗?编辑该问题并等待答案。
  • 我之前也发过类似的问题。但是,在运行之前的脚本之后,我重新定义了要安静地卸载的问题。我是堆栈溢出的新手,所以如果我做了不正确的操作,我深表歉意。

标签: powershell windows-installer wmi


【解决方案1】:

另外,您的流程拼写错误。应该是“msiexec”而不是“msicexec”

【讨论】:

    【解决方案2】:

    在“foreach”的行尾有一个不平衡的单引号。我怀疑修复这只是你问题的开始。祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多