Windows Task for restart if user not logged in
问题 I'm trying to create scheduled task for Windows reboot, which is executed if any user is not logged in. If user is logged in locally or over RDP, the machine should not be restarted. For unconditional restart, I have task in Task Scheduler with: Action: "Start a program", Program/script: "powershell", Add arguments: "restart-computer -force" For conditional restart I have powershell code: $ErrorActionPreference = "Continue" $userstatus = quser /server:'localhost' if(!$userstatus){ Restart