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)
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"
Unregister-ScheduledTask -TaskName "Restart_Once" -Confirm:$false
Remove-Item -Path "c:\ProgramData\Amagent\Restart_Once.cmd"
I’m new to Automox. Why do this instead of:
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.
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).
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
PUT YOUR CODE HERE
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.
Tom Aril Virak
I am very new to Automox.
Please show me how to setup the worklet to reboot both windows and linux endpoints.