powershell 卸载多个应用程序?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为
like
和应用程序名称之间没有空格,并且应用程序名称需要用单引号引起来。该部分应该类似于like '" + $AppName + "'"
。但是,您可以像这样更简单地执行整个脚本:
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 likelike '" + $AppName + "'"
.However, you could do the whole script more simply like this: