none
Howto create a ValidateSet with dynamic (runtime) values? RRS feed

  • Question

  • Hi Scripting Guys!

    I want to use the auto complete feature in my function for a specific parameter using a "dynamic" validate set (Similar to the Get-Service function and the Name parameter). 

    For example, instead of this:

    function Test-Function
    {
        Param
        (
            [ValidateSet("Folder1", "Folder2", "Folder3")]
            $Param1
        )
        # ...
    }

    I want to get the validate set populated by a function like all Folders from the C drive :

    function Test-Function
    {
        Param
        (
            [ValidateSet(ls c:\ -Directory | select -ExpandProperty Name)]
            $Param1
        )
        # ...
    }

    Any suggestions?

    Thanks,
    Martin

    Monday, September 8, 2014 8:57 AM

Answers

  • Funny you should ask. Martin Schvartzman has recently posted an example of exactly how to use dynamic validate set.

    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable)

    • Proposed as answer by jrv Monday, September 8, 2014 10:58 AM
    • Marked as answer by JisaakMVP Thursday, September 11, 2014 11:40 AM
    Monday, September 8, 2014 9:51 AM