使用PowerShell删除多个应用程序?

时间:2011-10-31 12:30:42

标签: powershell windows-installer wmi

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

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

$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 

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:-1)

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

相关问题