It could be a defective power supply, but then, it could be just about anything from power switch, hard drive, memory, cpu fan, bad cable, bad video graphics card, Virus, Spyware, adware, or bad registry or other Windows install defect.
First, get canned air such as Dust-Off, an thoroughly clean the CPU fan and heat sink, as well as the power supply fan.
It is possible to buy a power supply tester for $12 to $25 at most major online suppliers or local computer store. But then, a replacement power supply could be as low as $30 to $40.
These fixes are always slow going. You start out with the most likely options, replacing components, then keep running trials until you get to the fix that works.