1

I would like to create a .ps1 script that would open an Windows Terminal window with multiple tabs and in each tab a command to be executed ( kubectl logs -f "name_of_pod" ).

So I would basically want to automate my day to day process of opening Windows Terminal, getting a desired pod name with 'kubectl get pods -n 'your_namespace' command and then copy the pod name and open another Windows Terminal tab and execute kubectl logs -f 'name_of_pod' there. And I've got around 10 pods whose logs I need to monitor. And if Windows Terminal crash ( it happens ) I need to start again all.

So far I've managed to only open a new Windows Terminal tab and rename the tab via .ps1 script, but I can't pass the kubectl command - I am getting error "[error 2147942593 (0x800700c1) when launching.. "

Does anyone have any ides how to do this?

All best, D.

  • 1
    Can you include the script that you have so far? – Nick H. Jun 06 '22 at 13:58
  • This is what I got so far.. wt.exe --window 0 new-tab -p "Windows Powershell" --title "QA TEST" -Command "& {(`$kubectl get pods -n 'my_pod_name')}" I've even tried to create another .ps1 script where would i have kubectl command and call that .ps1 script instead writing the whole command like above in comment, but same thing. – ApprenticeOfCode90 Jun 07 '22 at 06:49

2 Answers2

1

I encountered this problem recently. I think the solution is to always pass the full path to the exact instance of Windows PowerShell you want to run to control which version is called and under what user context.

For example to run your kubectl command example, try this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe `
  -Command "& {(`$kubectl get pods -n 'my_pod_name')}"

Similar solution on this S/O answer https://stackoverflow.com/a/70548103/490787

gb96
  • 1,674
  • 1
  • 18
  • 26
0

I've found solution to this, if someone is still interested. The PowerShell command is:

wt.exe --maximized -w 0 new-tab --title "TAB 1" `; -p "Windows Powershell" --title "TAB 2" powershell -NoLogo -NoExit C:\Dragan\Startup\inv-pub.ps1 `;  -p "Windows Powershell" --title "TAB 3" powershell -NoLogo -NoExit C:\Dragan\Startup\inv-ca.ps1 `; focus-tab -t 0

To explain code above: I've created a .ps1 file for each of my kubectl commands, and I am calling them from one main .ps1 script, I know it is not pretty but it gets the job done for me. wt.exe is for opening windows terminal --maximized is for opening windows terminal maximized --title is for naming the windows terminal tab focus-tab -t 0 if for focusing desired tab from many ( in this case i am focusing first tab from many )