Use ValidateSet with the contents loaded from a CSV file

I know this post is quite old, but with Powershell 6.2 and above you can use a .NET class at the beginning of the script and have the set controlled by a csv for example.

This article hear does an excellent job of explaining: https://adamtheautomator.com/powershell-validateset/


Here is something you can start with:

function New-Name {
    param (
        [parameter(Position=0, Mandatory=$true)]
        [String]$Name
    )

    dynamicparam {
        $attributes = new-object System.Management.Automation.ParameterAttribute
        $attributes.ParameterSetName = "__AllParameterSets"
        $attributes.Mandatory = $true
        $attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute]
        $attributeCollection.Add($attributes)
        $values = @('MailBox', 'Tralala', 'Trilili') # your Import-Csv here
        $ValidateSet = new-object System.Management.Automation.ValidateSetAttribute($values)
        $attributeCollection.Add($ValidateSet)

        $dynParam1 = new-object -Type System.Management.Automation.RuntimeDefinedParameter("Type", [string], $attributeCollection)
        $paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
        $paramDictionary.Add("Type", $dynParam1)
        return $paramDictionary 
    }

     process { 'Foo' }
}

Credits where credits are due, this largely comes from the following article from the Scripting Guy. The code isn't pretty, but it does what you want.

completion