by bashluk at 2012-12-25 06:33:37
Background]by DonJ at 2013-01-01 12:09:11
I’m working on a PowerShell host application, creating the PS runspace.
Additionally, I have my own PS module, adding a few cmdlets, and a PS provider introducing its own PS drive containing child items.
My host application is responsible for user input processing, passing it to the PS engine, and displaying the output in some application’s window.
Since my application is just hosting the PS engine, it is responsible for the Tab completion of the user’s input.
For this purpose, I decided to invoke the PS’s TabExpansion function directly passing to it the required parameters, and then, using a circular buffer, presenting the function’s results to the user.
Problems]
1) TabExpansion works great completing the PS commands and their parameters, but it doesn’t produce any result when trying to complete the child item names inside my PS drive (my provider’s GetChildNames () handler is not called in this case):
<MY_DRIVE>:>Get-Item <itemName-prefix><TAB> - doesn’t work
<MY_DRIVE>:><commandName-prefix><TAB> - does work
Moreover, this problem exists only if hosting the PS by my application. If I run the standalone PS console of Microsoft, the child items of the new PS drive are completed pretty well.
2) I tried to install PS 3.0, where the TabExpansion was replaced by TabExpansion2 having absolutely different API.
So I adjusted my code now calling the new function and supplying to it new parameters and using the new type of returned values.
The new TabExpansion2 works in both scenarios - in the PS hosted by my application, and in the Microsoft’s console.
But how can I write the code that will compile and work on any target machine calling the TabExpansion or TabExpansion2 depending it’s PS 2.0 or 3.0 installed?
Note, that the return value class of TabExpansion2 cannot be referenced in my code, because this class was introduced at first in the assembly Automation.dll of the PS 3.0 only.
Sorry you’ve not seen a reply here… you may want to try asking at StackOverflow.com, or perhaps hitting up Keith Hall through his blog (http://rkeithhill.wordpress.com/) and see if he’s got any ideas.