It's also known as an 'inhibitor switch'. You haven't said what make/model of car you have, but the link below will show you generic images of the switch, which will be located on the side of the transmission:
automatic transmission inhibitor switch Google Search
Grab a flashlight and crawl under your car. Look on the side of the transmission unit. Disconnect the electrical unit and try cleaning all the contacts.
You can, if you know how, 'short out' the switch using a length of wire to bypass it. However, be aware that this can also allow the car to be started in Drive or Reverse.
Don't jump to conclusions and presume that it is the inhibitor switch. It may be a faulty sensor somewhere in the engine - the crankshaft sensor is usually the prime suspect which can cause the symptoms you describe, as can a faulty coil/ignition pack.
The best course of action would be to get someone with an OBD scanner - the handheld diagnostic machine - to connect it to your car and do a diagnostic check for you. Any error codes picked up by the OBD will identify the cause of the problem.
It is cheaper, easier and less hassle to get an OBD check done first than it is to replace parts in the hope of curing the problem.