Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, September 9, 2016 11:34 AM
I would like to be able to add a scheduled task to run a script/program at next computer startup and only run once.
Using the GUI i can add a task to run at startup, but it will run everytime the computer starts. I only want it to run once.
Besides that i want to schedule this using powershell. I know how to do that, but again i am unable to let it only run once.
Anyone have any idea how to accomplish this?
All replies (6)
Monday, September 12, 2016 2:42 AM ✅Answered
I have seen your same case on PowerShell forum, please notice Andy’s reply.
Regards
Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Friday, September 9, 2016 12:38 PM
Hello
You can use this
Register-ScheduledJob –Name AtStartup –FilePath C:\Scripts\Startup.ps1
-Credential (Get-Credential DOMAIN\Username)
-MaxResultCount 30
-ScheduledJobOption (New-ScheduledJobOption –DoNotAllowDemandStart)
-Trigger (New-JobTrigger –AtStartup)
You can also refer this link
Regards, Regin Ravi
Friday, September 9, 2016 12:55 PM
Hi thanks!
That is about what i have got also and that does work. The only thing i can't figure out is how to tell it to only let it run once and then delete/disable/stop. -MaxResultCount only determines how many enties to remember in history.
Friday, September 9, 2016 1:17 PM
Hi,
You can create an active setup in registry.
so that it will run only once for each user login.
Regards, Regin Ravi
Friday, September 9, 2016 1:40 PM
In our case the script needs to be run only once and before the fist user login, so using ActiveSetup or RunOnce is not an option.
Friday, September 9, 2016 2:11 PM
I guess it might be easier to adjust the script that needs to be run and add code to remove the scheduled task during the process. That way we could use the scheduled task that is setup to be run at startup and delete the task with the same script that is run upon startup.