Interactive PowerShell Menu - AD -HELP

Hi Guys,

I am trying to build an Interactive AD Menu script so that I can complete day to day task within my role.

I am struggling with the switch process and how it connects to the menu system.

I am struggling to seperate the questions that need to be asked when I run certain AD commands.

So for example, if you select option 1, it will ask you for a username and store it within the varible $CopyFrom. When this varible get’s called it reads out a text which displays to the user.

This works perfectly fine, but I am having issues with stopping it from coming up when selection other options.

So at the moment when I select option 4, it reads out the $CopyFrom varible.

I have been trying for ages to get a user to select something from the menu and it read out instructions on what to do with the command.

Hopefully all of this makes sense.

I have labled the code and seperated it, so it makes sense to you all.

Thank you.
Justin-Leslie

function Show-Menu
{

#Colours Varibles
$Selection = "Cyan"
$Questions = "Yellow"


#User Questions
    parm [string] $Title = 'AD Menu'
    Clear-Host
    Write-Host "======================= AD Menu ==========================" -foregroundcolor $Selection

    Write-Host "1: Copy AD Security Groups #1" -foregroundcolor $Questions
    Write-Host "2: New AD User #2" -foregroundcolor $Questions
    Write-Host "3: Disabled AD User Account #3" -foregroundcolor $Questions
    Write-Host "4: Get User Details" -foregroundcolor $Questions
    Write-Host "Q: Press 'Q' to quit" -foregroundcolor $Questions
    Write-Host "n" -foregroundcolor $Questions



#Sitches + Commands
    }
    DO
    {

    Show-Menu - Title 'AD Menu'
    $UserInput = Read-Host "Please make a selection" 
    $CopyFrom = Read-Host "What user do you want to copy from?"
    $CopyTo = Read-Host "User you are pasting to?"
    $UserName = Read-Host "What is the Users Name?"
    
    switch ($UserInput)
    
       {
           '1' 
              {Get-ADUser -Identity $CopyFrom -properties *| Select-Object MemberOf -ExpandProperty memberof | Add-ADGroupMember -Members $CopyTo}
          
           '4' {Get-ADUser -Filter {samaccountname -like "*$UserName*"}
        }
 
           'q' {EXIT}
       }
       pause
       Write-Host "Copy Completed!"
    }
        until ($UserInput -eq 'q')