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.




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

  • 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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