How can USB sticks be dangerous?
Take a look at this USB keyboard:
"But that's not a keyboard! That's an USB drive, silly!"
Actually, no. It looks like a USB drive to you, but when it gets connected to a computer, it will report that it is a USB keyboard. And the moment it is installed, it will start typing key sequences you programmed on it beforehand. Any operating system I know automatically trusts USB keyboards and installs them as trusted input devices without requiring any user interaction the moment they are connected.
There are various payloads available for it. For example, there is one which types the keyboard input to open a shell, launches WGET to download a binary from the Internet, and runs it.
Recently, a form of attack has surfaced which does not "hack" the computer through code or software vulnerabilities, but instead does actual damage to the electronics.
A creator known as Dark Purple created a device known as the USB Killer 2.0 (based on an earlier version created by him based on the same concept) which, when plugged into the USB slot of the computer, stores the small amount of power sent to the device in capacitors, and then sends the stored energy back all at once at -220 volts.
It keeps repeating this process until the computer is dead. This destroys the I/O controller, often built into the motherboard (and may cause other damage as well; I haven't read any details on extensive testing). (Original source in Russian and the Google Translated version.)
On the right, the exposed USB Killer 1.0 and its successor, the USB Killer 2.0, and on the left, the USB Killer in an enclosed case, which looks just like an ordinary USB flash drive.
The results are shown here, killing the motherboard of a Lenovo ThinkPad X60 just after being plugged in to the USB slot:
The "USB stick left outside the power plant" you are talking about sounds a lot like the Stuxnet affair. There was a surprising (and satisfying) amount of detail about the technical aspects in the book Countdown to Zero Day. If you are genuinely curious I would highly recommend reading it.
To give you a tl;dr for your question; it's not done with a script but rather an file crafted on a lower level to exploit vulnerabilities in the way that the operating system handles USB drives. When you plug a USB drive into Windows, it will try to do helpful things like assess the file structure and see if there are any files you might particularly want to use, in order to give you a prompt to immediately access those files. While it doesn't intentionally execute any of the files directly, there are exploits to the way the OS scans the files that can be used to trick the operating system into executing code.