Skip to main content

Worklet - Reboot Computer as System account

  • November 5, 2020
  • 8 replies
  • 455 views

Forum|alt.badge.img

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

  • Rookie
  • 3 replies
  • November 25, 2020

I’m new to Automox. Why do this instead of:
Restart-Computer
?


Forum|alt.badge.img
  • Author
  • Channel Partner
  • 8 replies
  • November 27, 2020

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.

image001.png

image002.jpg


Rich-Automox
  • Automox Employee
  • 29 replies
  • November 27, 2020

Restart-Computer -Force

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


  • Rookie
  • 3 replies
  • November 27, 2020

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).


Forum|alt.badge.img
  • Author
  • Channel Partner
  • 8 replies
  • November 28, 2020

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?


  • Rookie
  • 3 replies
  • November 28, 2020

Yes it should.

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

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

PUT YOUR CODE HERE

Stop-Transcript


Forum|alt.badge.img
  • Author
  • Channel Partner
  • 8 replies
  • January 4, 2021

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


Hi,

I am very new to Automox. 

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

Thanks. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings