2

I have set up a task manager task to run a script on my VM startup which runs multiple commands needed to get my React app with an express/mongodb backend running. Does anyone know what happens to the Powershell windows which are opened because when I log in there is nothing on my desktop. I hope this makes sense below is the script I am running. Thank you.


start cmd.exe /k pm2 ls

TIMEOUT 30

start cmd.exe /k pm2 resurrect

TIMEOUT 30

cd C:\Users\devuser\Desktop\product_manager\product_manager

start cmd.exe /k serve -s build

PAUSE

Robert Templeton
  • 139
  • 1
  • 2
  • 9
  • that does not look like powershell code ... it looks like CMD/Bat code. why are you using the `powershell` tag? – Lee_Dailey Jan 22 '20 at 15:14
  • Yeah it is a Bat File, I mostly work on mac so not sure what the difference is. I run these commands in powershell and it works. – Robert Templeton Jan 24 '20 at 08:12
  • please remove the powershell tags. those commands are all matching up with utilities that are from CMD. if you run them with a `.Bat` extension, they will run in `CMD.exe` _even if you start the Bat file in powershell. if you run them on their own in a powershell window, they will still call the CMD utils - Timeout.exe, Start.exe. only the `cd` and `pause` have powershell equivalents. [*grin*] – Lee_Dailey Jan 24 '20 at 14:49

1 Answers1

1

You are not saying, how you set up the scheduled task.

1 - When the computer starts

or

2 - When I logon

I am assuming that because you said...

run a script on my VM startup

... it's item 1.

Unless you specifically start PowerShell with 'NoExit', then calling powershell.exe will run whatever code you tell it to then close when done.

powershell -noexit -file SomeScript.ps1

PowerShell command line options

PowerShell[.exe] [-PSConsoleFile | -Version ] [-NoLogo] [-NoExit] [-Sta] [-Mta] ...

-NoExit

Does not exit after running startup commands.

Unless that code is still running when you logon, it's not supposed to be seen. Doing this on startup, then the code is not tied to a user session and you can only see sessions you started.

Just curious though... If you are using a Startup task, why do you want to see the powershell.exe console when you log on.

postanote
  • 15,138
  • 2
  • 14
  • 25
  • Yeah it is when the machine starts. So Im running my app via Node and Serve and I would need to be able to stop it/restart it if there is any issues and would need to see the powershell to be able to do that. Mostly it works fine with me being able to monitor it but im trying to handle the vm restarting when I am not here so that everything will reboot. – Robert Templeton Jan 22 '20 at 08:45
  • So, I'd suggest that you change it to item 2 and leveraging noexit, or to set the registry to run / auto startup if you need to interact with it for whatever reason. – postanote Jan 22 '20 at 08:49