title: Powershell - Copying File to Remote Host and Executing Install exe using WMI
body: <p>EDITED:  Here is my code now.  The install file does copy to the remote host.  However, the WMI portion does not install the .exe file, and no errors are returned.  Perhaps this is a syntax error with WMI?  Is there a way to just run the installer silently with PsExec?  Thanks again for all the help sorry for the confusion:</p>
  
  <pre><code>#declare params
  param (
  [string]$finalCountdownPath = "",
  [string]$slashes = "\\",  
  [string]$pathOnRemoteHost = "c:\temp\",
  [string]$targetJavaComputer = "",
  [string]$compname = "",
  [string]$tempPathTarget = "\C$\temp\"
  )
  
  # user enters target host/computer
  $targetJavaComputer = Read-Host "Enter the name of the computer on which you wish to install Java:"
  [string]$compname = $slashes + $targetJavaComputer
  [string]$finalCountdownPath = $compname + $tempPathTarget
  #[string]$tempPathTarget2 = 
  #[string]$finalCountdownPath2 = $compname + $
  
  # say copy install media to remote host
  echo "Copying install file and running installer silently please wait..."
  
  # create temp dir if does not exist, if exist copy install media
  # if does not exist create dir, copy dummy file, copy install media
  # either case will execute install of .exe via WMII
  #[string]$finalCountdownPath = $compname + $tempPathTarget;
  if ((Test-Path -Path $finalCountdownPath) )
      {
      copy c:\hdatools\java\jre-7u60-windows-i586.exe $finalCountdownPath 
      ([WMICLASS]"\\$targetJavaComputer\ROOT\CIMV2:win32_process").Create("cmd.exe /c c:\temp\java\jre-7u60-windows-i586.exe /s /v`" /qn")
      }
  else {
      New-Item -Path $finalCountdownPath -type directory -Force
      copy c:\hdatools\dummy.txt $finalCountdownPath
      copy "c:\hdatools\java\jre-7u60-windows-i586.exe" $finalCountdownPath
      ([WMICLASS]"\\$targetJavaComputer\ROOT\CIMV2:win32_process").Create("cmd.exe /c c:\temp\java\jre-7u60-windows-i586.exe /s /v`" /qn")
      }
  </code></pre>