I use this within a login script triggered with Jamf (Loginhook). This was the only working solution I have found to enable in school lab environment.
#!/bin/bash CURRENTUSER=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");') su "$CURRENTUSER" -c "defaults write /Users/ws/Library/Preferences/.GlobalPreferences AppleShowAllExtensions -bool true" su "$CURRENTUSER" -c "killall Finder"
Tested on MacOS 10.14.5 / 10.14.6