Can't get ssh-keygen to complete using Powershell [duplicate] - powershell

I have recently started working with Kubernetes and Docker and still new with how it all works. I have made a ps1 script to run all the steps I need to do to build image and execute image on Kubernetes.
What I see is all steps work fine on ISE (except this one: "kubectl exec -it test-runner pwsh"). For this step alone, I have to run it on another PowerShell window.
When I run this step in ISE, the script keeps running without ever giving any error or stopping.
Does anyone know if its a limitation with Kubernetes working on ISE or if there is a workaround to make it work?
Working with ISE is quick and saves me tons of time, so this really makes a difference when I have to copy, paste, enter this each time in a separate PowerShell window.
Thanks in advance for your help!
P.S: I looked at other suggested similar questions/answers and none of them seem to be related to Kubernetes not working on ISE. Hence this question.
command:
kubectl exec -it test-runner pwsh
Expected (and actual when running from PowerShell console):
----------------------
PS C:\windows\system32> kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /test>
-----------------------------
Actual (when running from PowerShell ISE):
PS C:\SourceCodeTLM\Apollo> kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
(with a blinking cursor and script running without breaking and changing to the new path)...
-----------------------------------------------

The PowerShell ISE doesn't support interactive console applications, which notably means that you cannot start other shells from it.
The ISE tries to anticipate that problem by refusing to start well-known shells.
For instance, trying to start cmd.exe fails with the following error message:
Cannot start "cmd". Interactive console applications are not supported.
To run the application, use the Start-Process cmdlet or use
"Start PowerShell.exe" from the File menu.
Note:
pwsh.exe, the CLI of PowerShell (Core) 7+, is not among the well-known shells, which indicates the ISE's obsolescent status. It is being superseded by Visual Studio Code with the PowerShell extension. Obsolesence aside, there are other pitfalls - see the bottom section of this answer.
However, it is impossible for the ISE to detect all cases where a given command (ultimately) invokes an interactive console application; when it doesn't, invocation of the command is attempted, resulting in obscure error messages or, as in your case, hangs.
As the error message shown for cmd.exe implies, you must run interactive console applications outside the ISE, in a regular console window.
From the ISE you can use Start-Process to launch a program in a new, regular console window; in the case at hand:
Start-Process kubectl 'exec -it test-runner pwsh'
Alternatively, run your PowerShell sessions outside the ISE to begin with, such as in a regular console window, Windows Terminal, or in Visual Studio Code's integrated terminal.

After digging out, I found a way to interact with the interactive console applications.
we can use SendKeys('key_here') to specific application.

You could open a command window from PowerShell and send the command to open the shell.
Start-Process PowerShell -Wait "-NoProfile -ExecutionPolicy Bypass -Command `"kubectl exec helloworld-web-8495f4c888-jw2tg -n local-v1 -it -- /bin/bash`""

Related

error appear when installing IBM Cloud CLI "'iex' is not recognized as an internal or external command..."

I'm trying to install IBM Cloud CLI but there is a problem faced me when I do this.
I added the Path to environment variables but it didn't work too !
This happens because the iex (shorthand for Invoke-Expression) command is a Powershell command, but it is entered to Command prompt. The latter is the old command shell that dates back to the MS-DOS days of the 80's.
One can tell the difference from the fact that the window title bar says Command Prompt, not Powershell. Often - not always! - a Powershell session has blue background and command has black.
To run Powershell commands, start a Powershell session either by typing powershell and pressing enter into a command session, or by opening Windows Start menu and typing powershell (followed by enter).

Certain Docker Commands not working in Windows Powershell ISE but working in other Command Line tools

I am exploring docker and I've been using Windows Powershell ISE to run docker commands. I have come across situation where I run certain commands in Powershell but they appear to be stuck, but when I run the same docker command on Command Prompt they work fine. I am using the same machine but different command line tools. Why do certain docker command work in powershell and some don't? The below are just some examples. While most work, some don't appear to be working.
Example 1) docker system prune
In powershell I expected a message like I do in the command prompt below, but it appears to be hanging.
Example 2) docker exec -ti containerName bash
In CMD Prompt, I am able to jump into my running container but not in Powershell
Docker does not support Powershell-ISE:
https://docs.docker.com/docker-for-windows/

Powershell and ssh when running rabbit

I have ssh on to a ubuntu box and run the following:
rabbitmq-server –detached
Which I believe should give me the command prompt back and run rabbit in the background, howerver it justs hangs:
Is this a powershell issue?
PowerShell is a component of Microsoft Windows, it has a command-line shell and a scripting environment. So I don't think you question is relative to PowerShell.

interactive powershell from Cygwin

I cannot run PowerShell.exe interactively in a Cygwin rxvt or mintty terminal. Seems any session using a /dev/tty? or /dev/pts? pseudo terminal device. An instance using the junky windows console device /dev/console or /dev/cons? will work.
cygstart /bin/bash -li
launches the console version in the cruddy Windows Command Prompt which is the only place I can get an interactive PowerShell.
Works. Rxvt doesnt:
Nor does mintty:
I've tried all the echo -e | powershell.exe and powershell.exe </dev/null
I'm assuming when I see answers on Stackoverflow on this they are using Console's ... or am I missing something?
Why I cannot run PowerShell 2 from Cygwin? seems to run fine, just gets powershell v3 when he wants v2 ... wish I had that problem.
I've developed a powershell wrapper to call powershell scripts and commands from a Cygwin terminal session but cannot get the interactive option to work (if you give the wrapper no script or commands then you want to go interactive). see https://bitbucket.org/jbianchi/powershell/wiki/ for info on the wrapper script. It works for most powershell.exe calls and even acts like a "she-bang" if used in the first line of the ps1 script.
Today, typing powershell at a Cygwin bash prompt just works.
If you need to run powershell inside cygwin/babun, follow https://code.google.com/p/mintty/issues/detail?id=56#c64 . Bascilly, downloard or compile https://github.com/rprichard/winpty, copy it to your $PATH and then run
console.exe powershell
This also works with batch scripts that invoke powershell inside.
The solution I've found is to use http://sergeybelous.com/ (main site) Proxy32 proxywinconsole.exe program. If this program is in the path, my poweshell.bash wrapper will call it which will let you work interactively with PowerShell.
First Install cygwin in your system.
After that type bash on powershell terminal and you can access cygwin terminal.
PS C:\Users\username\1and1> bash
username#LWMT-14R25Q2:/mnt/c/Users/username/1and1$
I'm afraid I can't answer your question, but maybe I can help you a little further on your way with this:
I believe this is related to this issue, as discussed on the MinTTY Issue #56.
It goes into great detail as to how common cmd.exe shell applications work and interact, so much as they detail how common unix applications using their TTY abstraction layer work differently than Windows command line applications.
Script for running powershell on Cygwin minty:
blahblah#blahblahbin $ cat pwrshl
#!/usr/bin/bash if [[ ! -f "$1" ]] then
echo "Usage: $0 <PowerShellScriptFile>"
exit fi
echo "\n" | powershell -Command "& {$(<$1)}"

Launching .exe from PowerShell window SOMETIMES causes it to be run in separate window, so I can't see output or get $lastexitcode

I am by no means a PowerShell expert; I have spent a good while googling this, but haven't found an answer.
The basic idea of my script is to run a Microsoft tool called appcert.exe with command-line arguments. appcert.exe returns 0, 1, or -1; I am checking it with $lastexitcode.
appcert.exe only runs on Windows 7 and Windows 8, so I have run my script on both.
Everything works fine on Windows 7x64 (PS version = 2.0). I can manually run all the same steps. I see the output of appcert.exe in the same PS window.
Different story on Windows 8x64 (RTM), where PS version = 3.0, CLRVersion = 4.0.30319.17929.
Sometimes, appcert.exe runs "inline" (like it did in Win7); other times, a command window is launched, the appcert.exe output flies by, and command window closes. The PS window that called it can't check $lastexitcode (which, by the way, is not set at all).
I tried all PS versions on machine, and results are as follows:
appcert.exe is launched in separate window in these instances:
In PowerGUI 3.2.0.2237 (uses PS 2.0)
In regular PowerShell (non-admin)
In Windows PowerShell ISE (non-admin)
appcert.exe is launched inline in these instances:
Ran Powershell as administrator
Ran ISE as administrator
Behavior above is obtained whether I:
Launch script, which calls the appcert command like this: & $CertToolPath
cd to the home direcotry of the tool and type .\appcert.exe
Run this: Cmd /c appcert.exe
Run this: Invoke-expression –command appcert.exe
Run this: [system.diagnostics.process]::start("appcert.exe")
My colleagues are equally stumped by this.
My machine is in a test domain, not a workgroup. I log into the machine as an admin of the test domain, so theoretically, I'm already an admin.
I install the MS tool as that admin, too. In fact, I never do anything as the machine's local admin. Any ideas? :)
Many thanks in advance,
Tania
Can you repro this with any other exe? Do you have UAC prompts disabled?
Is it possible that appcert.exe requires to be run as Admin, and if not, it automatically re-launches itself as Admin (this should cause a UAC prompt, but if you've turned them off, it would appear to just spawn a new instance automatically)?