【发布时间】: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