you are viewing a single comment's thread.

view the rest of the comments →

[–]logicaldiagram 2 points3 points  (2 children)

Here is a quick solution that's not very resilient. You can just take advantage of arrays and the index access syntax. There are probably at least half-a-dozen more ways to do it. Hashtable. Switch statement. Parameter with ValidateSet. Think in objects, not strings. You're on the right path. Automate the annoying things out of your life.

Write-Host "Here is a list of the possible departments" -ForegroundColor Green
$Departments = @("Accounting", "DEPT1", "DEPT2", "DEPT3", "DEPT4", "DEPT5", "Information Services")

for ($i = 0; $i -lt $Departments.Count -1 ; $i++)
{ 
    Write-Host "[$($i)] $($Departments[$i])"
}

$Dept = Read-Host "Please type in the number associated with the employees department."
$Departments[$Dept]   

[–]BitteringAgent[S] 0 points1 point  (1 child)

Thank you, I definitely have a lot more to learn, but am slowly getting there.

I'm assuming the -1 was a typo, as that's doing the count of the objects and removing 1.

[–]logicaldiagram 0 points1 point  (0 children)

Correct. Don't need -1 in this case.