A lot of different students use the laptops where I work and we have one set profile for them to use. The idea is that when the laptop logs on we can disassociate from the WiFi and also delete the password key that sits inside of the keychain access so each student can use their own WiFi username and password. I've managed to do this and I can do it manually through these commands:
#!/bin/bash
sleep 30
echo "sleep over"
sudo /usr/libexec/airportd en0 disassoc
sudo /usr/bin/security -v delete-generic-password -l networkalias
echo "disassociated"
First I give the computer about 30 seconds to reconnect to the wifi before disassociating and then I use the next command to delete the password that sits in keychain access. These commands work perfectly fine when I run each one manually, along with when I use "sudo jamf policy -event trigger" to force it for testing, but every time I let the command run itself on logon it disassociates but never deletes the password and lets you reconnect to the WiFi without typing in the new username and password. Any ideas on a fix for this?