Reputation: 43
I have created a GPO within a domain that runs a computer startup script (when the computer is turned on, it runs that script). What this script does is to create a scheduled task that restarts the computer every day at 23:00.
Here is the script code (it is a PowerShell script):
# We define the time we want the computer to restart
$triggerTime = "23:00" # 24 hours format HH:MM
# We create a new trigger that will be executed daily at the specified time
$trigger = New-ScheduledTaskTrigger -Daily -At $triggerTime
# We define the action we want the task to perform, in this case, restarting the computer
$action = New-ScheduledTaskAction -Execute "shutdown.exe" -Argument "/r"
# Specifies the options for running the task whether the user is logged in or not
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType S4U -RunLevel Highest
# We create the scheduled task with the specified options
Register-ScheduledTask -TaskName "Reinici" -Trigger $trigger -Action $action -Principal $principal -Description "Reinicia l'ordinador cada dia a les 23:00" -Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable)
All this works perfectly, on the computers that I assign the GPO, when I restart them to apply the policies, the task is created, and they restart at 23:00, and if they already have the task created it also works, but I need that on those computers, they log in automatically with a specific user, I think it can also be done from a PowerShell script that runs when the PC starts. If you need more information to know more, don't hesitate to ask, I might have left out some basic things to know.
I would be very grateful if you could help me.
Upvotes: 0
Views: 132