2

I'm trying to remove an application on a remote machine using the Invoke-Command cmdlet but it's not working.

Here is my script:

  Invoke-Command -ComputerName "Computername" -Verbose -ScriptBlock {
  msiexec.exe /x '{4ADBF5BE-7CAF-4193-A1F9-AM6820E68569}' /qn /passive
  }

Are there any reliable, working alternatives in this context?

carlpett
  • 12,203
  • 5
  • 48
  • 82
JoeRod
  • 899
  • 8
  • 20
  • 30

2 Answers2

3

This doesn't use Invoke-Command or MSIExec, but it's a functional uninstall method for removing applications on remote machines using WMI for anything registered with WMI (should be anything installed via msiexec).

(Get-WmiObject -Class Win32_product -ComputerName ComputerName -Filter {IdentifyingNumber LIKE '{4ADBF5BE-7CAF-4193-A1F9-AM6820E68569}'}).uninstall()

Additionally that can be put into a ForEach loop if you have several computers to do it on. If you have the Name, IdentifyingNumber, and Version listed in WMI you can make it much faster with the following context (using AT&T Connect Participant Application v9.0.82):

$App="IdentifyingNumber=`"`{1F3A6960-8470-4C84-820C-EBFFAF4DA580`}`",Name=`"AT&T Connect Participant Application v9.0.82`",version=`"9.0.82`""
([WMI]\\ComputerName\root\cimv2:Win32_Product.$App).Uninstall()

Yes, the $App string is horribly escaped, but that's due to the way WMI requires the string to be formatted with curly braces and double quotes and what not. This is not exactly useful for a single uninstall since it requires you to get all that info up front and format the key string. If you were going to remove a piece of software off 30 machines though, it would be much better. You can get all that info by just leaving off the .Uninstall() method from my first command, so...

Get-WmiObject -Class Win32_product -ComputerName RemoteComputer -Filter {IdentifyingNumber LIKE '{1F3A6960-8470-4C84-820C-EBFFAF4DA580}'}

Will spit back something like:

IdentifyingNumber : {1F3A6960-8470-4C84-820C-EBFFAF4DA580}
Name              : AT&T Connect Participant Application v9.0.82
Vendor            : AT&T Inc.
Version           : 9.0.82
Caption           : AT&T Connect Participant Application v9.0.82

Can also be used with the name, or even partial names by changing the filter to something like `{Name LIKE '%AT&T Connect%'} or you can query WMI to list all the applications registered with it by leaving the -Filter off completely, though you probably want to pipe that to Format-Table to make it readable. I used:

gwmi -class win32_product -computername RemoteComputer|ft IdentifyingNumber,Name,Version

A good read with more info about this can be found at this link

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
0

Here is the solution I came up with

$myses = New-PSSession -ComputerName "Computer" 
Invoke-Command -Session $myses -ScriptBlock {
#finds all instances of Java installed
$find_sep = gwmi win32_product -filter "Name LIKE '%Java%'" | select -ExpandProperty IdentifyingNumber
foreach($i in $find_sep){
msiexec.exe /x $i /qn /passive /l*v! c:\uninst.log
 }
}
JoeRod
  • 899
  • 8
  • 20
  • 30