Forcing Logout to kick off FileVault 2 in year 2018

Valued Contributor II

I need a way to force logout the user after FileVault2 has been enabled. I see some old post from 2014, but nothing new. Any ideas how to force log out the user which would be the local admin account once FileVault 2 has been kicked off.

I tried this didn't work


# Step 1: Log out Active User command.

CurrentUser=$(stat -f%Su /dev/console)
OtherActiveUsers=$( who | grep -v _mbsetupuser | grep -v ttys000 | grep -v "$CurrentUser" | sed 's/console.*//' )
loggedInUID=$( echo "$OtherActiveUsers" | while read userName; do
    id -u "$userName" 
    done )

echo "$OUsers" | while read userName; do
echo "$loggedInUID" | xargs /bin/launchctl asuser "$loggedInUID" sudo -iu "$userName" "/usr/bin/osascript -e 'tell application "loginwindow" to  «event aevtrlgo»'"

exit 0

and this


## Get the logged in user's name
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
## Get the PID of the logged in user
loggedInPID=$( ps -axj | awk "/^$loggedInUser/ && / {print $2;exit}" )

## Use the above to run Applescript command to logout using keystroke commands
/bin/launchctl bsexec "${loggedInPID}" sudo -iu "${loggedInUser}" "/usr/bin/osascript -e 'tell application "System Events" to keystroke "q" using {command down, option down, shift down}'"
Read My Blog: