Force-disconnect all remote users from Applescript or shell?

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.


enter image description here