Select specific program using variable as an input

Hi folks!
I am having problem with this question.
Get a specific program installed on your pc and then uninstall using powershell.
I can find the program with this: Get-WMIObject -ComputerName “mindell” -Query “SELECT * FROM Win32_Product where Name like ‘%Teams%’”

But I need to use a variable in my fucntion to write any name as an input then use $app.Uninstall()
But it is not working for me. Please can any one help me?

Hi,
As mentioned to me Get-WMIObject is depricated and you should use Get-CimInstance.

Also DO NOT QUERY Win32_Product

It will cause all products to run through the reinstall process as per:

If Configuration manager is used in your environment use: Win32reg_AddRemovePrograms

Otherwise you should query the uninstall key in the registry or compile the mof on the system first (not a fand of compiling mofs but giving options: Google:

Find Win32Reg_AddRemovePrograms on page

You would probably want to find the right regisrty path then put that into a hashtable so the UninstallString value can be returned the way you want.