I want to begin this one with a short warning, system is the highest access you can get in Windows and you can really break things here, keep that in mind and don't do anything stupid.
Now with the warning out of the way, why would you want to run something as the system account?
Normally you shouldn't do it but there are some instances where it can be very useful.
One such case is when testing a script that is going to be used by a software agent running on the computer. These agents usually run in the system context and if your script has not been tested for this it might not work as expected.
So how do I do it then?
The first thing you need to do is download a tool called psexec, you can find it at
https://learn.microsoft.com/sv-se/sysinternals/downloads/psexec
It will come as a zip file so before moving on you need to extract it.
There are lots of files in the zip, it is fine to extract all of them but the only one you need is psexec.exe. I usually put it in a folder at C:\tools but you can put it wherever
When extraction is done open a command prompt as admin and browse to the location of psexec, then use this command
psexec -i -s powershell
A new terminal will popup, this is your Powershell running in system context, you can test it by running the command
whoami
Remember to close the terminal once you are done with the testing
Happy scripting!