none
Conditional ArgumentCompleterAttribute for PowerShell 2.0 compatibility RRS feed

  • Question

  • I have a PowerShell script that has an ArgumentCompleterAttribute for one of its parameters.  How can I make the script compatible with PowerShell 2.0, while preserving argument completion on PowerShell 5.1?

    The rest of the script is already compatible with PowerShell 2.0 but the System.Management.Automation.ArgumentCompleterAttribute type does not exist in "System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", which is what PowerShell 2.0 is using.  That then causes a "Cannot find the type for custom attribute" error when I run the script on PowerShell 2.0.

    Friday, December 14, 2018 3:32 PM

Answers

  • I recommend either a) dispensing with PowerShell 2.0 compatibility or b) living with the limitation. Even if it's possible to do what you want, is it worth the engineering effort? (IMO it isn't)

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by ranta Friday, December 14, 2018 5:37 PM
    Friday, December 14, 2018 4:00 PM
    Moderator

All replies

  • What research suggests that it is possible?

    (My guess is that you can't do both.)


    -- Bill Stewart [Bill_Stewart]

    Friday, December 14, 2018 3:34 PM
    Moderator
  • I'm thinking perhaps I could replace the ArgumentCompleterAttribute with a Register-ArgumentCompleter call, which could then be done conditionally. But how can I get that executed early enough?
    Friday, December 14, 2018 3:38 PM
  • I recommend either a) dispensing with PowerShell 2.0 compatibility or b) living with the limitation. Even if it's possible to do what you want, is it worth the engineering effort? (IMO it isn't)

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by ranta Friday, December 14, 2018 5:37 PM
    Friday, December 14, 2018 4:00 PM
    Moderator