Using PowerShell engine for Tab completion

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 7 months ago.

  • Author
    Posts
  • #6158

    by bashluk at 2012-12-25 06:33:37

    Background]
    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):
    :>Get-Item – doesn't work
    :> – 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.

    by DonJ at 2013-01-01 12:09:11

    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.

You must be logged in to reply to this topic.