Running Powershell via cmd as administrator

I need to execute a powershell script using cmd. it is being implemented in a third party software’s scripting language. The commands in the PS script will require elevated privilege’s. when testing the command via a command prompt in administrator mode it works fine but if it’s a command prompt without administrator privledges it won’t work. So my question is how do i get the cmd command to run with elevated privilege’s?

the command i am using is cmd /C powershell -command E:\Scripts\ReloadApp.ps1 “Parms”
how do i get the cmd command to run the same as opening a command prompt as administrator? i have tried run as with runas /user:domain\myuserid and it prompts me for password and it runs fine. but this needs to run unattended from a scheduler (not task scheduler) under a service account.

as a side note, when i originally started this project i was using a unc path but kept getting an error there also. that command was cmd /C powershell -command \ServerName\Folder1\Scripts\ReloadApp.ps1 “Parms” this would give me the prompt Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. the file is not blocked and the execution privilege’s are set to ByPass so i don’t understand this issue either.

Any help you can provide this newbie is appreciated!

Welcome to the forum. :wave:t4:

A short internet search brought up this:

This results in the current script being passed to a new powershell process in Administrator mode (if current User has access to Administrator mode and the script is not launched as Administrator).

Thanks Olaf, but i have done plenty of short internet searches and have already read the suggested article. the issue using these approaches is all require some type of user intervention such as entering a password or answering the prompt of do you want this command to make changes to your machine. none of which work in an automated environment.

Only if the user does not have administrative rights on the computer. But in this case you’re pretty much out of luck. You cannot bypass the UAC.

Maybe it’s my lack of understanding of admin rights but i, as well as the account running the command from the scheduler already belong to the Administrators group on the servers. Or is there another set of administrative rights that i need to be in?

If I got it right - no. The account running the CMD has to have administrative rights on the computer.

good afternoon, you can write any script, then when creating a task in the scheduler, you simply specify on behalf of whom this script should be executed and if this account is an administrator, then everything will work, when creating a task there is a parameter, a tick to run with the highest privileges.
The account under which the task will be launched must be an administrator on remote PCs if it is supposed to be launched remotely. Again, the account must be a member of the local administrators group on the PC