feat: add validatepattern

This commit is contained in:
itsscb 2025-04-26 20:17:00 +02:00
parent d4341b3b40
commit 55d4504645
2 changed files with 4 additions and 1 deletions

View File

@ -120,7 +120,9 @@ foreach ($param in $paramBlock.Parameters) {
} elseif ($attr.TypeName.Name -eq 'ValidateSet') { } elseif ($attr.TypeName.Name -eq 'ValidateSet') {
$val.values = $attr.PositionalArguments.Value $val.values = $attr.PositionalArguments.Value
} elseif ($attr.TypeName.Name -eq 'ValidateScript') { } elseif ($attr.TypeName.Name -eq 'ValidateScript') {
$val.script = $attr.PositionalArguments.ScriptBlock.Extent.Text $val.value = $attr.PositionalArguments.ScriptBlock.Extent.Text
} elseif ($attr.TypeName.Name -eq 'ValidatePattern') {
$val.value = $attr.PositionalArguments.Value
} }
$validations += [pscustomobject]$val $validations += [pscustomobject]$val

View File

@ -21,6 +21,7 @@
# Accepts pipeline input by value # Accepts pipeline input by value
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'Set2')] [Parameter(ValueFromPipeline = $true, ParameterSetName = 'Set2')]
[ValidatePattern("^[a-zA-Z0-9]*$")]
[string]$InputObject, [string]$InputObject,
# Accepts pipeline input by property name # Accepts pipeline input by property name