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.

5
  • 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. Commented Feb 20, 2023 at 23:48
  • Thanks Alex, but the bash did not open. The kubectl command ran in the CMD itself. Commented Feb 21, 2023 at 2: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? Commented Feb 21, 2023 at 2: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 Commented Feb 21, 2023 at 5: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. Commented Feb 22, 2023 at 10:21

1 Answer 1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.