Quantcast
Channel: SAPIEN Forums
Viewing all articles
Browse latest Browse all 311

PowerShell • Function parameter based on value of another parmeter

$
0
0
Hello,
I got a problem with parameter in a function.
I try to pass a parameter based on the value of the precedent parameter :
- if the value of the parameter FieldName is Color
- the value of the parameter NewValue must be have a validateset attribut and can be choosen

For other value of the parameter of FieldName, the value is a free string

Below the code of the function, but the validate script attribut does not support a validateset attribut.

Code:

function Update
{

[CmdletBinding(SupportsShouldProcess = $true)]
[OutputType([hashtable])]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?')]
[string]$Url,
[Parameter(Mandatory = $true)]
[string]$Credentials,
[Parameter(Mandatory = $true)]
[string]$GroupName,
[Parameter(Mandatory = $true)]
[ValidateSet('Name', 'Description', 'Color', IgnoreCase = $false)]
[ValidateNotNullOrEmpty()]
[string]$FieldName,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateScript({ if ($FieldName -eq "Color") { [ValidateSet('Bleu', 'Gris', 'Orange', 'Rouge', 'Vert', IgnoreCase = $false)] } })]
[string]$NewValue
)

#TODO: Place script here

}
Thanks for your help.
Best regards

Statistics: Posted by yves22 — Fri Nov 17, 2023 12:18 am — Replies 3 — Views 430



Viewing all articles
Browse latest Browse all 311

Trending Articles