Connect to wifi network through command line

nmcli is a command‐line tool for controlling NetworkManager.

Disconnect:

nmcli d disconnect iface wlan0

Connect:

nmcli d wifi <WiFiSSID> connect password <WiFiPassword> iface wlan0

Just change wlan0,WifiSSID, WiFiPassword to reflect your setup.