This Worklet will reboot the computer using Scheduled Task running as System account.
Evaluation code: (returns exit code of 1 so that the policy will always run the remediation code when scheduled)
Exit 1
Remediation code:
New-Item -Path "c:\ProgramData\Amagent" -Name "Restart_Once.cmd" -ItemType "file"
Add-Content -Path "c:\ProgramData\Amagent\Restart_Once.cmd" -Value "shutdown -r -t 30"
$action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-windowstyle hidden c:\ProgramData\Amagent\Restart_Once.cmd"
$time = (Get-Date).AddSeconds(10)
$triggerAt = New-ScheduledTaskTrigger -At $time -Once
Register-ScheduledTask -TaskName "Restart_Once" -Trigger $triggerAt -Action $action -User "NT Authority\SYSTEM"
Start-Sleep 11
Unregister-ScheduledTask -TaskName "Restart_Once" -Confirm:$false
Remove-Item -Path "c:\ProgramData\Amagent\Restart_Once.cmd"