Controlled spin switching in a metallocene molecular junction