1

Are those files put into a cmd context and then just executed/typed ? A .bat file is just run, but a powershell file can`t just be run.

How can I make it run without bat file?

Elisabeth
  • 20,496
  • 52
  • 200
  • 321
  • I [still say](http://stackoverflow.com/q/35776256/1683264) you should use a [batch + PowerShell chimera](http://www.dostips.com/forum/viewtopic.php?p=45095#p45095). That saves you from having to deal with execution policies. – rojo Mar 03 '16 at 17:55

1 Answers1

4

You don't need a batch file (.bat or .cmd file). Just create a shortcut to %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -File whatever.ps1. You may need to use the -ExecutionPolicy parameter to allow scripts. Run powershell /? from a Cmd.exe or PowerShell prompt for more information.

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
  • But how do I know when I log into a server where the script is autostarted that IT IS indeed autostarted showing a date + time? Therefore I would like to have a bat calling the .ps1. But with the .bat are other probs waiting... – Elisabeth Mar 03 '16 at 19:28
  • What do you mean by 'IT IS indeed autostarted showing a date + time'? Are you talking about running something from the `Startup` folder, or...? (I think you need to clarify your question.) – Bill_Stewart Mar 03 '16 at 19:32
  • yes I want to run the .ps1 from startup folder. I want all the output of the .ps1 like Write-Host in the cmd window. So I can control what my script when something. – Elisabeth Mar 03 '16 at 19:35
  • Just run powershell.exe and specify the `-File` parameter to run a script. The PowerShell script will run in a console window. – Bill_Stewart Mar 03 '16 at 19:38
  • ok then I really got something wrong in my head. I will try and let you know! – Elisabeth Mar 03 '16 at 20:26
  • I did: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\Running_FileWatcher\filewatcher.ps1 -noexit -ExecutionPolicy Unrestricted then the window shuts down and my filewatcher does not work. Should the window not stay open? – Elisabeth Mar 03 '16 at 21:52
  • @Elisabeth Try adding -WindowStyle Maximized as well if your relying on the script output to be shown to the user. – runcmd Mar 03 '16 at 22:07
  • 2
    Make sure that the `-File` parameter is last on the powershell.exe command line. (The /? help, `powershell /?`, tells us this explicitly.) – Bill_Stewart Mar 03 '16 at 22:12