I want to create a menu with show-menu that will depend on what is present on the computer.
I want to list in the menu usernames available on c:\users\ (based on the folders names).
For example : in c:\users there is folder nammed :
homer.simpson
lisa.simpson
bart.simpson
and with show-menu ask the user to choose one of them by typing 1 for homer.simpson 2 for lisa.simpson etc ..
How can i do it ?
Thank you in advance !
EDIT : Code
$users = Get-ChildItem "$env:SystemDrive\Users"| ForEach-Object { $_.Name }
foreach ($user in $user) {
$user
$num++
New-Variable -Name "a$num" -Value $user
#Get-Variable -Name "$user$i"
}
function Show-Menu
{
param (
[string]$Title = 'Please select an user'
)
cls
Write-Host "================ $Title ================"
Write-Host "1: $a1"
Write-Host "2: $a2"
Write-Host "3: $a3"
Write-Host "Q: $a4"
}
do
{
Show-Menu
$input = Read-Host "Please make a selection"
switch ($input)
{
'1' {
cls
'You chose option #1'
} '2' {
cls
'You chose option #2'
} '3' {
cls
'You chose option #3'
} 'q' {
return
}
}
pause
}
until ($input -eq 'q')