Thought Process
This is a pretty textbook problem. You want to have an array of departments, and then display the array to the user with an integer corresponding to the element's index + 1.
You then receive an integer input from the user corresponding to a department (with a bit of error checking to ensure they enter an integer that actually corresponds to a department) and then use that integer to get the appropriate array element from the departments array. Since input from Read-Host is a string by default, you need to cast $UserInput as an [int] before using it to get the index of an array.
Again, since we're listing the values to the user using array index + 1, we must consider that when retrieving the array element from the array, hence why we subtract 1 from the value obtained from the user.
Code
# Our array of departments
$Departments = @(
"Music",
"Science",
"PE",
"Maths"
)
# List each department for the user to pick from, being sure to off-set it's array index by 1
foreach($Department in $Departments){
Write-Host "$([array]::IndexOf($Departments, $Department) + 1). $Department"
}
# Get the appropriate value that corresponds to a department from the user, retry if user entered invalid value
do {
$UserInput = Read-Host -Prompt "Enter the number corresponding to the desired department"
} while ($UserInput -le 0 -or $UserInput -gt $Departments.Length)
# Once we have a value from the user, use it to assign get the appropriate department, make sure to offset it by 1
$SelectedDepartment = $Departments[[int]$UserInput - 1]
Write-Host "User selected department: $SelectedDepartment"
Example Execution and Output
1. Music
2. Science
3. PE
4. Maths
Enter the number corresponding to the desired department: 0
Enter the number corresponding to the desired department: 5
Enter the number corresponding to the desired department: 4
User selected department: Maths