0

I have to start a .ps1 when a specific ID come. So I used the Task Scheduler and my script starts correctly!

I'm starting powershell.exe with the arguments -File C:\Users\ostefanini\Documents\powersh\backup_started.ps1 -WindowStyle Maximized.

But… the PowerShell window does not appear. I tried to reveal it with "YAPM" (and old task manager on windows, with the ability of reveal window's task) but the program cannot perform this operation.

So, how to see my PowerShell window? (I finished my script with cmdlet pause).

And the second question, in direct relation with the first one, because my script finish by a "pause" it's never ended. If my task starts again, my script didn't run because of double instance.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Oscar
  • 1,071
  • 13
  • 26
  • Why are you pausing the script and waiting for user intervention? I'm guessing so you can see the script output to check something happened or didn't? If so, it's better practice to log the output to a file then you can let the script run and just check the file if you need to. Removing the pause and using logging would answer both of your questions. Here's a good answer with a logging function: http://stackoverflow.com/questions/7834656/create-log-file-in-powershell – henrycarteruk Nov 17 '16 at 09:37
  • Thanks, Of course it's not a great idea, but I would like to see my powershell window... – Oscar Nov 17 '16 at 09:38
  • Fair enough, can you share the command you're using in Task Scheduler to start the script? – henrycarteruk Nov 17 '16 at 09:39
  • Okay, I see the option -WindowStyle from here: https://msdn.microsoft.com/fr-fr/powershell/scripting/core-powershell/console/powershell.exe-command-line-help I tried the argument "Normal" but nothing appear. here is my line: powershell.exe and arguments: -file C:\Users\ostefanini\Documents\powersh\backup_started.ps1 -WindowStyle Maximized. But I noticed that my explorer.exe restart two or three times – Oscar Nov 17 '16 at 10:33
  • How is your scheduled task configured exactly? – Ansgar Wiechers Nov 17 '16 at 11:26
  • Euhm... right click -> create a new task ? (I exported it: http://pastebin.com/iLh18ceu) – Oscar Nov 17 '16 at 12:53

1 Answers1

1

Okay, I found all solutions. First, to make a schedule task visible, select your schedule task, then right-click and choose "properties". In the tab "general", section "security options" choose "Execute only if the user is connected" and don't choose "Execute also if the user was not connected". It's because the task scheduler will not appear window... if no one will see it ^^

and second, for the problem of double instance, it's the default configuration of the process of creation task scheduler. To change it, go (on the same properties window) to the tab "Parameters" and choose in the last dropdown list "Execute a new instance in parallel" Sorry it's in french (sorry it's in french)

Oscar
  • 1,071
  • 13
  • 26