I have a script which takes lots of input from user. I need to validate those inputs. The issue I am currently facing is that if one of the input fails validation, the user should be prompted to re-enter only that particular input and rest all valid inputs should remain as is
Sample Code :
Function Validate
{
Param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidateLength(3,5)]
[String[]]$Value
)
}
$Value = Read-Host "Please enter a value"
Validate $Value
Write-Host $value
$Test = Read-Host "Enter Another value"
Write-Host $Test
Here when validation fails for $Value it throws exception and moves to take second input.