There's 2 things I'm trying to get accomplished.
- I'm attempting to list all the values of an array to a user while having that list numbered.
- I'm attempting to assign a value to a variable, depending on what the user chooses.
# List that prints array items for a user to choose from
$Array = @('A', 'B', 'C', 'D', 'E', 'F')
foreach($i in $Array)
{
Write-Host "|" $i #this | character should be a list from 1-6, listing all the groups in the array
}
Write-Output "Please enter which group:"
$Array = Read-Host -Prompt " "
# Assign value to the variable
$x = Read-Host "Please enter a number"
$Array = @('A', 'B', 'C', 'D', 'E', 'F')
$i=0
while ($i -lt $x) {
$i++
if ($i -eq $x) { continue }
}
$x = $Array[$i]
Write-Host "You're assigned to group " $x
I've figured this dirty way of doing it, but I was trying to see if there was a simpler way of doing this (someone mentioned multidimmensional arrays). The 2 pieces of code should work together, explaining the same variable assignment.
Thanks!
EDIT 1: I want the user to not have to input "0" for the A group.