Reputation: 27
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.
Upvotes: 1
Views: 2869
Reputation: 27
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 )
Upvotes: 0
Reputation: 1694
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
Upvotes: 1