Worklet - Reboot Computer as System account

  • 5 November 2020
  • 8 replies

Userlevel 1

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"

8 replies

I’m new to Automox. Why do this instead of:

Userlevel 1

A simple Restart-Computer does not work, thus I had to create this worklet.

Probably because Automox runs as system account, running a restart using task scheduler as system account seems to work tho.



Userlevel 5

Restart-Computer -Force

Should suffice since it suppresses the user prompt that is probably getting squashed.

Yep. Verified. I tried just Restart-Computer but it wasn’t working, so I tried it with some Transcripts/logging enabled and it was erroring that it wouldn’t reboot because there were users(s) logged in.

Restart-Computer -Force overrides the logged in user(s).

Userlevel 1

Hm, ok.

Restart-Computer -force did not work for me before I created this Worklet.
Does it work if a user is locked or No user logged on?

Yes it should.

Do something like this to figure out where you’re running into problems:

Stop-Transcript | out-null
$ErrorActionPreference = “Continue”
Start-Transcript -path C:\Windows\temp\My-Log-File.log -append



Userlevel 1

I stand corrected, Restart-Computer -Force works. I don’t know why it did not work before creating this worklet, but it works now.
I’ve testet with logged on user, locked computer and logged off user and the computer restarts every time.

Guess this worklet is unnecessary then.

Kind regards
Tom Aril Virak


I am very new to Automox. 

Please show me how to setup the worklet to reboot both windows and linux endpoints.