title: How to run powershell script from .ps1 file?
body: <p>I'm trying to automate the execution of a simple PS script (to delete a certain .txt file). Obviously, I'm new to powershell :)
  When I run the code in shell, it works flawless. But when i save the code as a .ps1 and double-click it (or execute it remotely), it just pops up a window and does nothing.</p>
  
  <p>I've tried to save the code as a .bat file and execute it on Windows command line, but it behaves the same: Works by coding directly on prompt, but doesn't Works by executing the .bat file.</p>
  
  <pre><code>$Excel = New-Object -ComObject Excel.Application
  $Workbook = $Excel.Workbooks.Open('H:\codes\test1.xlsm')
  $workSheet = $Workbook.Sheets.Item(2)
  $str_name = $WorkSheet.Cells.Item(2,1).Text
  Remove-Item -Path "H:\text files\$str_name.txt" -Force
  </code></pre>
  
  <p>I expected it to work by double-clicking it, just as it does by running in shell, or in the command line, but i can't figure out why it doesn't.</p>