2

Hi I've got a Script and are trying to start it in Task Scheduler.

this poses Two problems for me.

  1. is that the script will activate a Application that requires the GUI to be running and shown. so how can I make Task Scheduler to log in to windows automatically at a specific time. The computer will never/rarely be turned off or rebooted.

2. I have yet to Successfully start a Powershell script from the Task Scheduler. I've tried Following:

powershell.exe -noexit -executionpolicy bypass -command &'Y:\Run Test\StartPowershellScript.ps1'

And

 powershell.exe -noexit -ExecutionPolicy Bypass -File 'Y:\Run Test\StartPowershellScript.ps1'

And a variation of the above.

powershell.exe -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'

and I've tried some variations with and without &"" &'' & and so on.

now I'm not really sure if it can be done. but I hope I can get some help here.

Edit 1. I just tried the following.

powershell -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'

after I did this in powershell.

set-executionpolicy -scope Process -executionPolicy Unrestricted -force
set-executionpolicy -scope CurrentUser -executionPolicy Unrestricted -force
set-executionpolicy -scope LocalMachine -executionPolicy Unrestricted -force

However How do I make sure that this will persist after the computer has been rebooted ?

Edit 2. as it seems I can't make Scheduled task log in or unlock the computer, is there Anyway to set up a task to run at a specific time to log in to the computer so the scheduled task can run at this time ?

1
  • I wonder why I get a -1 for this I've done tons of research and still to this day I have problems with moving this from one working computer to another even thou I did the same as back then. this is a problem still for me I can't get scheduled task to even execute the script, except for that first computer, now I'm moving it to another computer and I got the same problem... Commented Dec 9, 2013 at 13:01

1 Answer 1

2
  1. You can't log into the GUI with a scheduled task. Enable automatic logon if you need an interactive desktop.

  2. Remove -NoExit from the argument list, otherwise PowerShell will keep running after the script completes. Also replace your single quotes with double quotes.

The execution policy is persistent unless it's superseded by a local or group policy (in which case Set-ExecutionPolicy should throw an error) or you're logged in with a temporary profile.

If that doesn't help you need to provide more details. Doesn't the task start at all? Do you get an error? What do the task history and eventlog say? What is the output of Get-ExecutionPolicy?

Sign up to request clarification or add additional context in comments.

3 Comments

I made the 2. question run after I made the Set-Executionpolicy like descriped above in the Edit section. I'll remove the -NoExit when I'm sure everything runs. I am a little sad to hear I can't log in with a scheduled task I'm on a computer that is in part of a domain where I can't just change the log off or the Lock computer behavior so it's imperative for the scheduled task to run correctly to be able to log in or unlock the computer.
I'm not sure if the group policy for the domain resets it but everytime I reboot the computer I have to set-executionpolicy again
I'm going to mark yours as the correct answer. as the part with powershell was answered before you by myself And that you didn't provide a solution to the login problem but just stated that it can't be done So far you are correct I've found no way to log in. I hope to find a solution still but maybe this is not the place for this type of question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.