1

I have a command that I need to execute from Git Bash in Administrator mode.

Is there a way I could create a Windows Batch file or PowerShell to do these steps?

At the moment I'm doing the following:

  1. In the Windows Explorer GUI, right click on Git Bash, and select, 'Run as administrator'.
  2. Type the command kubectl port-forward svc/camunda-operate 8081:80 -n camunda and press ENTER.

I've found, here, a way to launch Git Bash from cmd.exe, but I was unable to get it running elevated, and pass the command to Git Bash.

Compo
  • 36,585
  • 5
  • 27
  • 39
Praveen Kumar
  • 113
  • 3
  • 11
  • something like `"%PROGRAMFILES%\Git\bin\sh.exe" --login -i -c "kubectl port-forward svc/camunda-operate 8081:80 -n camunda"` Probably wrap that up in a runas /user:admin command. – Alex T. Feb 20 '23 at 23:48
  • Thanks Alex, but the bash did not open. The kubectl command ran in the CMD itself. – Praveen Kumar Feb 21 '23 at 02:12
  • I thought that was the desired effect. To get Bash to run in CMD and execute your command with a script. Was there an error message? – Alex T. Feb 21 '23 at 02:41
  • There was no error on the window.. I will try to use it for a some time and see if it is doing the same as using the Git Bash – Praveen Kumar Feb 21 '23 at 05:32
  • kubectl and bash scripts used work very nicely WSL2. If possible I would move the work with kubectl to WSL2 and use bash there, instead of using Git bash. – rob2universe Feb 22 '23 at 10:21

1 Answers1

0

From PowerShell:

Start-Process -Verb RunAs "$env:ProgramFiles\Git\git-bash.exe" '-c "kubectl port-forward svc/camunda-operate 8081:80 -n camunda"'
  • This launches an elevated Git Bash session, invariably in a new window.

  • Note that the new window closes automatically when the launched kubectl command terminates.

mklement0
  • 382,024
  • 64
  • 607
  • 775