1

I'm using the [ValidateSet()] parameter attribute to validate that the input received by a user is included in the set of approved input values. However, I was wondering if there was a way of adding helper text to appear in the console when hovering over a given value included in the set.

function Get-ObjectAction 
{
    [cmdletbinding()]
    param(
        [parameter(
            ParameterSetName = 'Interactive'
        )]
        [switch]$Interactive,

        [parameter(
            ParameterSetName = 'NonInteractive',
            HelpMessage = "Select the Object to Synchronize: '0 = Users, Contacts and Groups', '1 = Users only', '2 = Contacts Only', '3 = Groups only'"
        )]
        [ValidateNotNullorEmpty()]
        [ValidateSet(0, 1, 2, 3)]
        [int]$Option
    )
}

When I run the function in the console, auto-complete displays the available options, though I was wondering if there'd be a way to associate some helper text that would appear next to the autocomplete values for better usability.

Also, when declaring a validate parameter attribute (eg ValidateSet, ValidateNotNullorEmpty, etc.) the HelpMessage specified seems to be skipped, and an exception related to PowerShell's inability to validate the parameter input is thrown instead. If the first question doesn't have a feasible answer, is there a way to forego the exception related to the parameter validation and prompt the user with the help message instead?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Are you looking for [comment-based help](https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Core/about/about_Comment_Based_Help)? – Ansgar Wiechers Dec 09 '16 at 22:34
  • 1
    `HelpMessage` is displayed only if you enter `!?` when PowerShell asks you to supply values for missing Mandatory parameter. – beatcracker Dec 10 '16 at 00:36
  • Thanks beatcracker, that definitely answers the second part of my question. –  Dec 10 '16 at 01:24
  • Hi Angsar, what I was wondering was if powershell offers a way to present some text when you hover over acceptable parameter values that pop up in the console via intellisense. Thanks. –  Dec 10 '16 at 01:27

0 Answers0