I am trying to create a job that runs at startup on Windows Server 2012 R2 Core. The job runs a script that connects to a network shares and then mounts a VHD located on that share.
The script itself works and when registering with the
-RunNow parameter the job is fired and runs as expected. Running the job with the
Start-Job Cmdlet also works fine.
However, the job does not fire at startup like specified in its trigger.
What I did to create the job:
$Trigger = New-JobTrigger -AtStartup $JobOptions = New-ScheduledJobOption -RunElevated -RequireNetwork Register-ScheduledJob -FilePath C:\Scripts\Test.ps1 -Name Test -Trigger $Trigger -ScheduledJobOption $JobOptions -RunNow
I can clearly see the results of it working after doing this. But when restarting the server the results aren't there, but the job says it was last run not long after the reboot.