The answer to your question is "eelectromagnet". Electromagnets only produce a magnetic field when they have an electric current nearby, and are some of the more powerful magnets on Earth, running things such as MRI machines, and junkyard manet cranes. They also are part of why electric motors spin.