The ISE is for all intents and purposes just like the VSC code pane. Code written in the ISE script pane, like VSC code pane is not auto executed when hitting enter, like things are in the ISE console pane. In the ISE and VSC code panes, you have to explicitly select and run code in the panes or save and run the code in the pane.
The VSC integrated PoSH terminal (if you are using it, it’s the DOS cmd prompt by default), is like the PoSH console host, so it will respond the same way.
The ISE console was ‘not’ designed to be an integrated console. Unlike the PoSH console host and VSC integrated terminal - PoSH console. You cannot run integrated commands in the ISE console as you can in VSC PoSH console and the PoSH console host.
The moment you hit enter in the ISE console that means, execute what I just typed before the enter. Hence the errors you are seeing. So, you have to take a different tact with the ISE console host. The ISE console host is for single line commands with all properties, switches, etc. and running pre-built/saved scripts, and as an output window for what you run from the script pane. Note, you could send output to another ISE pane, notepad, etc. as well. In the ISE, there is little reason to write script-like things in the ISE console. That is what the script pane is for.
Again, the ISE console host is not the PoSH console host and will not act the same way. That was never it’s design.
Like you all, I ran into this in the early days of the ISE, but I learned quickly what to do when and where.
If you are using one-liners, literal specific one-liners, you can use the ISE script pane or the ISE console pane.
If you are writing scripts / functions / modules, use the ISE script pane. I would say do the same thing when using VSC.
Remember there are two PoSH terminals in VSC, depending on how you have it set up. If you set PoSH as you intergrated terminal, it is the same as the PoSH console in operation. However, you can set the terminal to be the PoSH Integrated version (think ISE console host) and it responds the same way as the ISE console host.
In the VSC with the default startup and PoSH set as the terminal (only 1 PoSH terminal listed in the drop down box), you get this…
$host
Name : ConsoleHost
Version : 5.1.16299.98
InstanceId : 7d9b1336-aea8-4e98-86fc-c81d462f779f
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Get-Process |
>>
If you set VSC to use the integrated PoSH terminal (2 PoSH terminal listed in the drop down box), you get this.
PowerShell Integrated Console
PS C:\Users\postanote> $host
Name : Visual Studio Code Host
Version : 1.5.1
InstanceId : a7d55c08-c508-4f43-b8fd-baa977e9c830
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData :
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PS C:\Users\postanote> Get-Process |
An empty pipe element is not allowed.
At line:0 char:0
PS C:\Users\postanote>