Force-disconnect all remote users from Applescript or shell? I have a mac that I want to automatically restart every night, but it is regularly accessed remotely from other machines in the house, and if anyone is still connected when it needs to restart it displays a prompt that it will disconnect remote users if the restart is allowed, and then just sits there waiting for a response.

Is there any way, possibly using Applescript or shell, to force a restart and automatically disconnect any remote users?
The following example AppleScript code works for me in macOS Catalina to restart the system and click the Restart button on the "There is a user sharing this computer. If you restart they will be disconnected" dialog that shows if Users accessing File Sharing on the machine are connected.

tell application "Finder" to restart
repeat 5 times
    try
        tell application "System Events" to click UI element "Restart" of window 1 of application process "loginwindow"
    end try
    delay 1
end repeat


Obviously the number of loops is arbitrary as is the value of the delay command. As coded it's allowing for five seconds for the dialog to appear, if it at all does.