title: Starting VB Script from Powershell script - works from PS environment, but not scheduled task
body: <p>I'm trying to ensure a process is running on my machine, so I decided to setup a scheduled task to check &amp; restart it hourly if no longer running.  The challenge is it's a Java process started via a vb script (yuk!).  The biggest original hurdle was starting it in the correct working directory so Java was happy, but I ironed that out.</p>
  
  <p>I figured out how to track the process and restart if needed.  This ps1 script works perfectly if I run it directly from within the powershell environment.</p>
  
  <p>LNGS_restart.ps1 --></p>
  
  <pre><code>$cmdArgs='/c cscript "C:\Program Files (x86)\LNGoogleCalSync\lngsync.vbs"';
  $workingDirectory="C:\Program Files (x86)\LNGoogleCalSync\";
  
  #Do select-string twice so we exclude the commandlet that actually finds the pattern (since that shouldn't count as a hit!)
  if( -Not (WmiObject Win32_Process | select commandline | Select-String -pattern 'lngs' | Select-String -pattern pattern -notmatch -quiet))
  {start -FilePath cmd.exe -ArgumentList $cmdArgs -NoNewWindow -WorkingDirectory $workingDirectory }
  </code></pre>
  
  <p>Running the above from within powershell environment works great.  Running it from command prompt or scheduled task doesn't work (won't start the process, it just does nothing and returns).</p>
  
  <pre><code>c:\jobs&gt;powershell c:\jobs\LNGS_restart.ps1
  </code></pre>
  
  <p>What is going on?  I'm not sure why it won't work outside powershell environment and how to fix it so that I can then schedule it via task scheduler</p>
  
  <blockquote>
    <p>Program/Script:  powershell.exe</p>
    
    <p>Arguments: -command "c:\jobs\LNGS_restart.ps1"</p>
  </blockquote>
  
  <p>Any help?</p>