3

I have a .ps1 file which needs to be run in administrative mode for it to work. But unfortunately I couldn't find a way to do that using Jenkins. Currently I am running this powershell command in execute batch command on Jenkins with all possible options. But it's not working.

Matteo Guarnerio
  • 720
  • 2
  • 9
  • 26
Krishna Prasad S
  • 141
  • 2
  • 17

4 Answers4

3

Easy hack to solve this was indeed adding a .bat file that was run from the Jenkins(Execute windows batch command). The bat file had following command which did run the powershell script with elevated(admin) rights

powershell -ExecutionPolicy Unrestricted -File your_script.ps1 --settings_skipverification=true
Krishna Prasad S
  • 141
  • 2
  • 17
1

Execute it with Invoke-Command via Jenkins.

Invoke-command -FilePath Script.ps1
Prasoon Karunan V
  • 2,916
  • 2
  • 12
  • 26
1

Since Jenkins is running as service, you can open services.msc and right click on Jenkins. Then click Properties, go to Logon tab, check mark This account and enter username and password which has admin privileges. Stop and Start Jenkins service.

From now on when you will run powershell commands in Jenkins, they will be run as administrator.

Matteo Guarnerio
  • 720
  • 2
  • 9
  • 26
0

Invoke with "Execute powershell step" as

$arg = "-file C:\filename.ps1"
start-process powershell -verb runas –argumentlist $arg
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Jonathan
  • 41
  • 1
  • 2
  • 7