This topic contains 3 replies, has 2 voices, and was last updated by
November 24, 2013 at 2:05 pm #11655
*edit: I must have been doing something wrong. I was getting no helpful information from this node: $psise.CurrentPowerShellTab.ConsolePane. Yet when I explored this using Raimund AndrÃ©e's VariableExplorer, the info was there. Thanks anyhow!
I'm looking to customize my ISE a bit. One piece I'm missing is the ability to extract text and contextual information from the console pane. For example, if I've typed up a command but have not executed it yet, I want to click a function and take action based on that function (similar to how F1 opens help in a window). I can use code to do this for the editor pane from this handy post.
I've tried writing a scriptblock to serialize $psise, putting in some random commands in the PowerShell pane, and pressing the shortcut to the scriptblock... I don't see anything in the resulting object that resembles the commands I had typed up.
I'm assuming that this is possible, and that F1 uses the same functionality to open help for a command...
Your insight would be greatly appreciated!
November 25, 2013 at 5:02 am #11656
So it turns out $psise.CurrentPowerShellTab.ConsolePane (appears to be) the right spot to pull this information, but pressing a shortcut somehow changes the environment so that this object does not include the information I need.
Does anyone know how to pull this? Here's a basic example of what I am looking for. I open PowerShell ISE (v3+). I type in the shell (not editor) "Get-Help Get-Command -Full". I do not press enter. I press a shortcut key, or click through the Add-Ons menu and pre-written code takes action based on the input "Get-Help Get-Command -Full", and the current position of the caret.
What am I missing? Do I need to invoke a method of some sort that sets the context back to the console before looking at $psise.CurrentPowerShellTab.ConsolePane? Is this functionality not possible?
November 25, 2013 at 5:17 am #11658MemberPoints: 0Rank: Member
I suspect that it's not possible if you're executing PowerShell code, because all code that you execute (even if you press a shortcut key) is run through that same Console pane. The ISE just saves whatever text was on the command line first, and puts it back when your shortcut code is done.
I'm not sure if it's possible to write extensions to the ISE in the form of a .NET Assembly rather than PowerShell code; extending the ISE isn't something I've researched yet. If it is possible, that might get around this problem.
November 25, 2013 at 5:39 am #11661
I notice if I type in a command in the console pane and press F1, I see a 'running script / selection...' status. Was hoping that meant the functionality was possible and that MS was using it for the help window
The topic ‘Getting the current input text from PowerShell ISE’ is closed to new replies.