question

anujachandgude-9814 avatar image
0 Votes"
anujachandgude-9814 asked MotoX80 edited

how to run as admin powershell.ps1 file calling in batch file from scheduled task

I'm running a batch file including the below command from the scheduled task using Bamboo. But I'm not able to process it because it is being stuck.

powershell.exe -noprofile -NoExit -command "&{start-process powershell -ArgumentList '-NoExit -noprofile -file \"%~dp0psfile.ps1\"' -verb RunAs}"

When we run the same batch file from local it opens up one dialogue asking for allowing permissions, as shown below.

96923-permission-dialogue.jpg

Can you please help me resolve this? This batch file internally calls .PS1 script which runs using RS jobs in parallel threads.


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 edited

I'm running a batch file including the below command from the scheduled task using Bamboo. But I'm not able to process it because it is being stuck.


I have no idea what Bamboo is or does. You might want to explain more about that and how it is being used.

In the Task Scheduler, define the task to run as an account that is a member of the administrators group. To prevent UAC issues, select "run with highest privileges".

https://www.digitalcitizen.life/use-task-scheduler-launch-programs-without-uac-prompts/


96943-capture.jpg



 powershell.exe -noprofile -NoExit -command "&{start-process powershell -ArgumentList '-NoExit -noprofile -file \"%~dp0psfile.ps1\"' -verb RunAs}"


You don't need to do that. Just have the 1st PS run the script.

 powershell.exe -noprofile -file "%~dp0psfile.ps1"

You may also need to add an execution policy if you have not set it globally.

 powershell.exe -noprofile -ExecutionPolicy Bypass -file "%~dp0psfile.ps1"


Normally you would not want to use -NoExit switch because that will leave Powershell.exe running after the script has terminated. You'll end up with a bunch of PS exe's running and doing nothing other than using up memory.







capture.jpg (49.5 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, I tried the above solution.. Not working as we need to create a scheduled task and that task needs to be run externally.

However, what I want is EXeternally Bamboo is used as a scheduler to a job(which runs PS script from git) on the agent or remote machine. When that PS script is called and PowerShell is opened to run that script on agent/remote machine, we will run it as administrator without UAC prompt.

0 Votes 0 ·
MotoX80 avatar image MotoX80 anujachandgude-9814 ·

EXeternally Bamboo is used as a scheduler


What is Bamboo? Is that a Microsoft product?

Is this what you are looking for?

https://docs.bamboosolutions.com/document/configuring_uac_for_workflow_conductor/


0 Votes 0 ·