Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to run a powershell script automatically in Elevated mode?

I am trying to automate some post-image tasks without user intervention, but am getting caught with the UAC. Is there a way to "bypass" this, possibly by running as another user?

I want the machine to reboot and run various scripts, so it can complete the build process with no intervention.



share|improve this question

Startup scripts run with elevated privileges. Can you add your script to the Startup scripts in Computer Configuration/Windows Settings/Scripts (startup/Shutdown)?

I'm sure there are other ways to pass credentials but this has worked for me in the past

share|improve this answer
Is there a way to programatically add a script to the local startup scripts folder? Say I have 3 scripts to run - coul I add a line in script A to copy script B to the startup script folder and delete script A and then add a line in Script B to copy script C to the scripts folder and delete Script B? – Ben Jun 24 '10 at 13:24
can you expand on this? Have added it in there, but it doesn't want to play. :-( – Ben Jun 24 '10 at 15:51
Are there any errors in the event log? Where is the file loacated? – Dave M Jun 24 '10 at 18:54
File is located in c:\windows\system32\grouppolicy\machine\scripts\startup (computer is back at the office so will check the log tomorrow) - Thanks, Dave. Ben – Ben Jun 24 '10 at 19:23

Here is an example of a self elevating PowerShell script.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.