Function two validationsets

Hi Folks,

Would appreciate soms helpen in building a PS function.
Want to run a script to connect and select my device(s) and select the command (s) to run via validationsets

I am not able to select the second validationset.

This is what i made .

function Get-ValInfo
        # Param $Val help description
                   ParameterSetName='Parameter Set 1')]
        [ValidateSet("10.149.x.x", "10.149.x.x")]

        # Param $Command help description
                   ParameterSetName='Parameter Set 2')]
        [ValidateSet("ls /data", "pwd ", "more /app/Appli/application.log")]

        $PlinkPath = "D:\Tools\PuTTy\PLINK.EXE"
        $User      = "me"
        $Pwd       = "xx"
        $Log       = "D:\Output.log"
        Set-Alias  plink $PlinkPath

echo yes | plink -ssh $Val -l root -pw $Pwd -m $commands | Out-File -FilePath "$Log"


Please edit your question to fix the formatting of the code.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

What exactly does that mean? Could you elaborate a little more detailed? The validate set for your parameter $Val contains two identical values. Why?

Why do you want to use 2 parameter sets?

Hallo Olaf,

The code is now ok . new here :slight_smile:
This function is to quickly select an value for my variable in the dropdown menu .

I want to run commands to serveral hosts ($val) by selecting them from the validateset , and in the second set also select which command ($command) by selecting form the dropdownbox.


Dropdown menu? Are you talking about the intellisense in the ISE or VSCode?

OK, and what’s the problem?

And why are you using 2 parameter sets? Parameter set and validate sets are two independend/different things. Are you sure you’ve got them right?

Yes indeed, ntellisense in the ISE.
I am new to powershell, the problem is that $commands dont show in intellisense

OK. Let’s start small. Just for testing - change your function to this:

function Get-ValInfo {
        [Parameter(Mandatory = $true)]
        [ValidateSet("10.149.x.x", "20.149.x.x")]
        [Parameter(Mandatory = $true)]
        [ValidateSet("ls /data", "pwd ", "more /app/Appli/application.log")]


`$Val: '$($Val)'

`$Commands: '$($Commands)'


Where do you define this function? … in your profile?

If it is defined you can type

How does that look?

Great olaf, is working now as I wanted