title: PowerShell and Excel Issue when Automating
body: <p>I am facing a curious problem.</p>
  
  <p>When I ran this code :</p>
  
  <pre><code>$Excel = New-Object -Com Excel.Application 
  $book = $Excel.Workbooks.Add()
  [threading.thread]::CurrentThread.CurrentCulture = 'en-US'
  sleep 10
  $book.saveas("c:\Temp\test.xlsx")
  $Excel.quit()
  Stop-Process -Name "Excel*"
  </code></pre>
  
  <p>in PowerGui, POwerSHell host..anywhere, it works beatiful.</p>
  
  <p>If I put into a  .bat and calls powerhsell  "c:\temp\excel.ps1" works fine too.</p>
  
  <p>But If i try to schedule this guy into schedule task  or run by a sql server job type cmd the error happens :</p>
  
  <p>Message
  Exception calling "SaveAs" with "1" argument(s): "SaveAs method of Workbook cla
  ss failed"</p>
  
  <p>Only when It is called by SQL Server Jobs ( that is a simple cmd command too and the line is the same as the .bat  powerhsell  "c:\temp\excel.ps1" ) the error happens.</p>
  
  <p>What it can be ? I tried  change the fileformat..etc..and nothing</p>
  
  <p>Thanks Guys :)</p>