0

First of all, thanks for looking at this. I'm new to scripting, so this is probably a rookie mistake that I'm making. I want to put the product keys in manually at the top, and then for each of the keys I want it to check if they are installed and uninstall them if they are.

I am trying to put the get-wmiobject list of product keys into a variable, and compare it against the list of product keys I have listed. If there is a match I want it to uninstall that product key.

And because of the specific problem that I'm tackling (with user/system installations on SCCM being all mixed up) I need to use the wmi query and not check the registry.

$keysToMatch = @("productKey1","productKey2")

$installedApps = @(Get-WmiObject win32_product | select IdentifyingNumber)

foreach ($key in $keysToMatch) {
    if ($installedApps -contains $key) {msiexec /x "$key"}
    }

Thanks for any help

Matt

EDIT: I should probably mention that it returns nothing. Even when I change the 'if' statement to write-host "uninstalling $key"

Matt H
  • 1
  • 2
  • `$installedApps = @(Get-WmiObject win32_product | select -ExpandProperty IdentifyingNumber)` – Matt Mar 11 '16 at 11:42
  • I'm googling '-expandproperty' right now, because that made everything work. Thank you so much! – Matt H Mar 11 '16 at 11:45

0 Answers0