Hi,
I am unable to select from the multiple options as I am getting invalid selection, even If I am entering correct parameters
cls
do
{
Write-Host " 1. test volume"
Write-Host " 2. DS_Local_Vol_1"
Write-Host " 3. Exit"
Write-Host
$answer = read-host "Select the desired option (Ex.1)"
$answer = $choice -match '^[123]+$'
if ( -not $answer) { write-host "Invalid selection" }
} until ( $answer )
if ($answer -eq 1)
{
$volname = 'test'
}
if ($answer -eq 2)
{
$volname = 'DS_Local_Vol_1'
}
if ($answer -eq 3){Exit}
Please help!!!!
Your RegEx will not only match 1 but also 11, due to the + in there.
Your changing the $answer to a Boolean with the -match expression.
Try like this
do
{
Write-Host " 1. test volume"
Write-Host " 2. DS_Local_Vol_1"
Write-Host " 3. Exit"
Write-Host
$answer = Read-Host "Select the desired option (Ex.1)"
$correct = $answer -match '^[123]$'
if (-not $correct) {
write-host "Invalid selection"
}
} until ( $correct )
if ($answer -eq 1)
{
$volname = 'test'
}
elseif ($answer -eq 2)
{
$volname = 'DS_Local_Vol_1'
}
elseif ($answer -eq 3){
Exit
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Your RegEx will not only match 1 but also 11, due to the + in there.
Your changing the $answer to a Boolean with the -match expression.
Try like this
do
{
Write-Host " 1. test volume"
Write-Host " 2. DS_Local_Vol_1"
Write-Host " 3. Exit"
Write-Host
$answer = Read-Host "Select the desired option (Ex.1)"
$correct = $answer -match '^[123]$'
if (-not $correct) {
write-host "Invalid selection"
}
} until ( $correct )
if ($answer -eq 1)
{
$volname = 'test'
}
elseif ($answer -eq 2)
{
$volname = 'DS_Local_Vol_1'
}
elseif ($answer -eq 3){
Exit
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much for your quick help