* Create a new job trigger. Here, I am introducing a delay of 10 mins.
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:10:00
* Schedule the job
Register-ScheduledJob -Trigger $trigger -FilePath C:\Some-Path\StartStopServices.ps1 -Name StartStopServices
View the scheduled job
* Open Task Scheduler and navigate to Microsoft => Windows => PowerShell. You can find here, the newly scheduled job.
* Open its properties. Since, the script will check the state of some Windows Services on startup. I’ll select the ‘Run with highest privileges‘ option.
* Go to the Action tab and select Edit Action. Here, you can see that it’s the PowerShell, which will be fired at the startup, and it contains the script path as argument along with some other properties.
* Finally, at the time of saving, admin password box will be prompted. This is because, I have marked the job to run with the highest privileges.