powershell是否要卸载多个应用程序?

powershell是否要卸载多个应用程序?,powershell,wmi,powershell-2.0,uninstallation,wmi-query,Powershell,Wmi,Powershell 2.0,Uninstallation,Wmi Query,我是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 an

我是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"

你知道我该怎么做吗

我认为这是因为
like
和应用程序名之间没有空格,应用程序名周围需要单引号。该部分应该看起来像“+$AppName+””

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

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

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

Void引起了我的问题,所以我使用了这个:$App=Get Content“C:\temp\un installApp.txt”gwmi win32_product |其中{$App-contains$\.Name}| foreach{$\.Uninstall()}用@manojlds edit尝试一下。
[Void]
如果我将管道括在括号中就可以了。是否有“请勿重新启动”的问题“通用命令行标志?或者这是一个特定的计划?(脚本正在工作,但它在我不希望的时候重新启动了我的机器!)@granadaCoder没有
Uninstall()
方法的选项。您可以将
foreach
更改为使用
msiexec
。它看起来类似于` foreach{msiexec.exe/norestart/q/x$\.identificationnumber REMOVE=ALL}请参见: