I've found two great tricks and I'd really like to get them to work together, but how to do so is totally eluding me.
One I just found is this: https://stackoverflow.com/a/2611394/12943 which is a batch file that starts powershell and feeds itself to powershell which is awesome.
the other trick is this one: https://stackoverflow.com/a/18739839/12943 Which lets PowerShell elevate itself if necessary (Feeding the script to itself once elevated)
I think it might work if the first line of the batch file that looks like this:
@findstr/v "^@f.*&" "%~f0"|powershell -&goto:eof
instead looked something like this:
@findstr/v "^@f.*&" "%~f0"|powershell "start-process powershell -verb runas" -&goto:eof
but that doesn't work and I can't quite get it right (I think the piping in that case goes to the original powershell process but not the one you runas).
The two methods obviously won't easily work together because they use similar mechanisms, but I can't help think that there is a clean solution that will both let me easily run a powershell script by typing the name into a command window AND self-elevate--both without any prior setup or extra software (since this is the first step of some system-configuration scripts on a system that cannot be attached to the internet).
I can (and will) do this by simply using the batch file solution and requiring the user to elevate manually but it seems like there should be an easier way.
Note that the batch file seems to also get around the executionpolicy which is somewhat curious but in this case preferred.