title: Using Powershell Invoke-Command on remote session to invoke executable by string
body: <p>I want to write a Powershell script to invoke an executable on a remote machine by its path and then wait for it to finish running. This is what I've got so far:</p>
  
  <pre><code>$executable = "C:\Temp\example.exe"
  $session = New-PSSession -ComputerName VIRTUALMACHINE
  $job = Invoke-Command -Session $session -ScriptBlock {$executable} -AsJob
  Wait-Job -Job $job
  </code></pre>
  
  <p>Instead of running C:\Temp\example.exe, the remote machine runs the string $executable - not exactly what I was going for here!</p>
  
  <p>How do I fix this?</p>