title: Powershell uninstall program with msiexec
body: <p>I've run into a problem getting msiexec to remove java with Powershell.  I've output my resultant command to the screen and pasted it into a batch file and it runs great.  But when it's executed via Powershell it fails saying the "package cannot be found".  Can anyone spot what I might be doing wrong? I've looked up and down google and tried a few different ways of executing the command w/o success and with the same result.</p>
  
  <pre><code>cls
  $java = Get-WmiObject -Class win32_product | where { $_.Name -like "*Java*"}
  $msiexec = "c:\windows\system32\msiexec.exe";
  #$msiexecargs = '/x:"$app.LocalPackage" /qr'
  $msiexecargs = '/uninstall "$app.IdentifyingNumber" /qr /norestart'
  
  if ($java -ne $null)
  {
      foreach ($app in $java)
      {
          write-host $app.LocalPackage
          write-host $app.IdentifyingNumber
          #&amp;cmd /c "msiexec /uninstall $app.IdentifyingNumber /passive"
          #Start-Process -FilePath $msiexec -Arg $msiexecargs -Wait -Passthru
          [Diagnostics.Process]::Start($msiexec, $msiexecargs);
      }
  }
  else { Write-Host "nothing to see here..." }
  Write-Host "check end"
  </code></pre>
  
  <p>The goal is to use the Windows 7 logon script to remove all versions of Java on end-user systems and then install the latest.  I prefer to make it all Powershell, but if I can't get this working I'll just use a batch file hard coded with the uninstall GUID's</p>
  
  <p>The write-host statements are all for the purpose of debugging, I'm just interested in the execution of msiexec in some variation of this format:  msiexec /x {GUID} /passive /norestart</p>
  
  <p>The error I get is:
  "This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package."</p>
  
  <p>I know it works on its own, just not in this script...so I'm thinking it's a syntax thing.</p>
  
  <p>If you have any questions let me know.</p>