both functions works fine SEPARATELY but not together

Hi Guyz

I am trying to write a simple script to list locked accounts and when the user provides the numbers needed to unlock

# Import Active directory Module import-module activedirectory # get user $name = Read-Host " Please enter the first name or last name for the user " $users = Get-ADUser -Filter "name -like '*$name*'" -Properties * function generate-table { $n = 1 $target = @(foreach ($u in $users) { [PSCustomObject] @{ '#'=$n++ 'Name'=$u.Name 'Username' = $u.samaccountname 'lockedout' = $u.lockedout } }) return $target } function Ask-user { $victim= Read-Host " Please enter the user's number you want to unlock" return $target | Where-Object { $_.'#' -in $victim } | select -Property name, username } generate-table Ask-user 

both functions works fine SEPARATELY but when i run the whole thing together it shows as follow

Please enter the first name or last name for the user : test entry Please enter the user's number you want to unlock: 

it doesn’t show the table 1st then ask the 2nd question, can you advise what is the issue? and what i am doing wrong?

submitted by /u/m_anas
[link] [comments]

Leave a Reply