title: Using Powershell invoke-expression to uninstall Java on all domain computers
body: <p>I can ps-session to a remote machine, run the following, and successfully uninstall Java:
  <code>invoke-expression "msiexec /q /x '{26A24AE4-039D-4CA4-87B4-2F83218025F0}' "</code></p>
  
  <p>I am trying to create a script that will uninstall from all domain computers:</p>
  
  <pre><code>Import-Module ActiveDirectory
  function uninstallJava {
  $badcomp = @()
  $CompList = Get-ADComputer -Filter 'name -like "*"' | select -ExpandProperty Name
  foreach ($c in $CompList) {
  
  Try {
  Enter-PSSession -ComputerName $computer 
  Invoke-expression "msiexec.exe /q /x '{26A24AE4-039D-4CA4-87B4-2F83218025F0}' "
  }
  
  Catch {
  $badcomp += $c
  }
  
  }
  
  }
  uninstallJava
  "the following servers could not be reached:"
  $badcomp
  </code></pre>
  
  <p>I don't receive any errors, but it doesn't uninstall Java from the remote machines.</p>
  
  <p>Any ideas appreciated.</p>