title: Uninstall Applications Via PowerShell
body: <p>I have been working this for a couple days now, and no matter how I run this and work it, it seems to uninstall the program via PowerShell and returns the success code:</p>
  
  <pre><code>__GENUS          : 2
  __CLASS          : __PARAMETERS
  __SUPERCLASS     :
  __DYNASTY        : __PARAMETERS
  __RELPATH        :
  __PROPERTY_COUNT : 1
  __DERIVATION     : {}
  __SERVER         :
  __NAMESPACE      :
  __PATH           :
  ReturnValue      : 0
  PSComputerName   :
  </code></pre>
  
  <p>This happens with various notoriously difficult to remove software such as McAfee.</p>
  
  <p>The command being used is:</p>
  
  <pre><code> Get-WmiObject -Class win32_product -Filter "Name like '%McAfee%'" | ForEach-Object {$_.Uninstall()}
  </code></pre>
  
  <p>I've tried various scripts, solutions here, and variations of these (such as below).</p>
  
  <pre><code>$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString
  
  $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString
  
  if ($uninstall64) {
      $uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
      $uninstall64 = $uninstall64.Trim()
      Write "Uninstalling (x64)..."
      start-process "msiexec.exe" -arg "/X $uninstall64 /qb" -Wait
      }
  if ($uninstall32) {
      $uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
      $uninstall32 = $uninstall32.Trim()
      Write "Uninstalling (x32)..."
      start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}
  </code></pre>
  
  <p>Even something simple like Yahoo Messenger, the command fails to uninstall the application when run from a Powershell Window as Administrator yet returns a success code and/or is no longer present on the WMI application list. </p>