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?
I think it’s because there is no space between
likeand 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: