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

发布于 2024-12-12 20:36:46 字数 1189 浏览 1 评论 0原文

我想创建一个脚本来删除一堆应用程序。我希望在启动脚本后无需用户交互即可执行此操作。

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

$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 

I want to create a script to remove a bunch of apps. I want to do this without user interaction once I've started the script.

This is the script I have so far; it doesn't work but hopefully you can see what I'm trying to do:

$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}'

This is the error that occurred:

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人海汹涌 2024-12-19 20:36:46

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

You have an unbalanced single quote on the end of the line with the "foreach." I suspect fixing that is only the start of your problems. Good luck.

情场扛把子 2024-12-19 20:36:46

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

Also you have the Process misspelled. Should be "msiexec" not "msicexec"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文