1

I want to run example.ps1 from code.bat

I realize that the start command would run it but require that it be run as admin, how can I do this?

1 Answer 1

4

In your batch file:

powershell -Command "&{ Start-Process powershell -ArgumentList '-File C:\folder\psfile.ps1' -Verb RunAs}"

...basically you're using Powershell to run Powershell. The second instance is elevated to Admin and is running your script with those permissions.


Full explanation:

Start-Process can be used to run a program, and also has the parameter -Verb RunAs which elevates the program to run as Admin.

We can't call Start-Process from a batch file as it's a PowerShell command.

But we can run powershell from a batch file, then using the -command parameter to run Start-Process.

We use Start-Process to run powershell (again) and run your script when it is elevated to Admin: -ArgumentList '-File C:\folder\psfile.ps1' -Verb RunAs

Sign up to request clarification or add additional context in comments.

5 Comments

I've gotten this far.
powershell -noprofile -command "&{ Start-Process powershell -ArgumentList '-NoProfile -File %path%Resources\Found\WindowsSecurity.ps1' -Verb RunAs}"
Thanks for your help already! Could you explain just slightly more? :D
Glad I could help, if you're happy with my answer you can Mark it as Accepted.
Thank you for being so kind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.