On UAC-enabled systems, to make sure a script is running with full admin privileges, add this code at the beginning of your script:
Now, when running your script, it will call itself again and attempt to elevate privileges before running. The -elevated switch prevents it from repeating if something fails.
You may remove the -noexit switch if the terminal should automatically close when the script finishes.