powershell 卸载多个应用程序?

发布于 2024-12-12 21:40:46 字数 755 浏览 3 评论 0原文

我是 PowerShell 新手,正在寻找一种卸载多个应用程序的方法。我在文本文件中有一个要卸载的应用程序列表。这是我到目前为止的代码:

# Retrieve names of all softwares to un-install and places in variable $app

$App = Get-Content "C:\temp\un-installApps.txt"

# Cycle through each of the softwares to un-install and store in the WMI variable

Foreach ($AppName in $App)
{
    $AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
    $AppNames = $AppNames + $AppTmp
}

foreach ($Application in $AppNames )
{
    msiexec /uninstall $Application.IdentifyingNumber
}

以下几行导致了问题

$AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
$AppNames = $AppNames + $AppTmp"

我有什么想法可以让它工作吗?

I'm new to PowerShell and I'm looking for a way to un-install multiple applications. I have a list of applications in a text file that i want to Un-install. Here's the code i have so far:

# Retrieve names of all softwares to un-install and places in variable $app

$App = Get-Content "C:\temp\un-installApps.txt"

# Cycle through each of the softwares to un-install and store in the WMI variable

Foreach ($AppName in $App)
{
    $AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
    $AppNames = $AppNames + $AppTmp
}

foreach ($Application in $AppNames )
{
    msiexec /uninstall $Application.IdentifyingNumber
}

The following lines causes the issues

$AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
$AppNames = $AppNames + $AppTmp"

Any ideas how i can get this to work?

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

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

发布评论

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

评论(1

樱桃奶球 2024-12-19 21:40:46

我认为这是因为 like 和应用程序名称之间没有空格,并且应用程序名称需要用单引号引起来。该部分应该类似于 like '" + $AppName + "'"

但是,您可以像这样更简单地执行整个脚本:

$App = Get-Content "C:\temp\un-installApps.txt"

gwmi win32_product|
    where { $App -contains $_.Name }|
    foreach { $_.Uninstall() } | out-null

I think it's because there is no space between like and the application name, and there needs to be single quotes around the application name. That part should look like like '" + $AppName + "'".

However, you could do the whole script more simply like this:

$App = Get-Content "C:\temp\un-installApps.txt"

gwmi win32_product|
    where { $App -contains $_.Name }|
    foreach { $_.Uninstall() } | out-null
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文