log out all users powershell script?

log out all users powershell script?

looking for a script that logs off any logged in users on windows. Closest thing I found to be useful to be used in EPC>>
  1. $regex = '(?<=\s+)\d+(?=\s+[a-z])'
    $quserOutput = quser
    $quserOutput | Select-String -AllMatches $regex | ForEach-Object {
        $sessionId = $_.Matches.Value
        logoff $sessionId
    }

    exit 0

So far, it works most of the time but, EPC will report that it errored executing the script.

When it executes successfully however, it does not work as expected (appears to do nothing)

Ideally I'm looking for a script that would execute successfully every time and log all users off. And NO, simple reboot is not an acceptable solution.

Hoping the community may have a solution.
Thank you

                New to ADSelfService Plus?